Banging my head against a wall here ... Been stuck on this for a while now ...
I have this query:
include 'dbconnect.php';
$user1id=$_SESSION['userid'];
$stmt=$db->prepare("SET @chatroom_ID=(SELECT ID FROM chatroom
JOIN chatroommembers ON chatroom_ID=chatroom.ID
WHERE chatroommembers.user_ID=:user1id
ORDER BY chatroom.ID
LIMIT 1);
SELECT user_ID FROM chatroommembers
WHERE chatroom_ID=@chatroom_ID
AND user_ID!=:user1id
LIMIT 1;");
$stmt->bindValue(':user1id',$user1id,PDO::PARAM_INT);
$stmt->execute();
$user2id=$stmt->fetchColumn();
echo $user2id;
What it is supposed to do, is find the chatroom ID that the current user is in, and echo out the user id of the second person that is in the room (There is always only 2 in the room)
The query works in PHPmyadmin ... But not in my PHP script
I can echo $user1id no problems
If I replace the query with a simple SELECT statement it works, for example:
SELECT user_ID FROM chatroommembers WHERE user_ID=:user1id
I've tried pretty much everything I can think of, and this statement just doesnt want to work ...
No errors are being outputted (I've even made it wrong to make sure my errors will output, which they did).