0

I'm trying:

$mysqli = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$usernames_results = $mysqli->query("SELECT username FROM users WHERE user_id = $member_id") or trigger_error($mysqli->error);
while($user_row = $username_results->fetch_object()) {
// do stuff with$user_row
}

This always returns FALSE. I'm certain $member_id is not null and that it does exist in the database. I ran the SQL query directly on the database and it returns the correct result. The error I get is

Fatal error: Call to a member function fetch_object() on a non-object`

when calling fetch_object() on $usernames_results.

$mysqli is also defined correctly because this works:

$conversations_results = $mysqli->query("SELECT UserID, ConversationID FROM Conversation_Members WHERE UserID = $user_id");

I have tried looking at $mysqli->error but it's empty.

What am I doing wrong in the first query?

This question has been wrongly marked duplicate before. Please do not mark this as a duplicate unless you're certain the suggested duplicate answers my problem.

Youssef Moawad
  • 2,846
  • 5
  • 28
  • 50

0 Answers0