Tuesday, August 28, 2018

php - Fatal error: Call to a member function fetch_assoc() on a non-object (mysqli)

I just switched my webhoster and tried to deploy my PHP application there. Unfortunately it crashes during the login process with this error message:



Fatal error: Call to a member function fetch_assoc() on a non-object in /home/infobo9/www/xxx/login.php on line 41


This is the code:




$DB = new DB;
$mysqli = $DB->getMySQLiObject();

$sql = "SELECT ios_worker.username, ios_worker.prename, ios_worker.lastname, ios_worker.partnerid_fk, ios_worker.workerid, ios_worker.password, role.rolename, role.roledescription, ios_partners.accessToAdminPortal FROM ios_partners join ios_worker on ios_worker.partnerid_fk = ios_partners.partnerid join workerrole on workerrole.workerid_fk = ios_worker.workerid join role on workerrole.roleid_fk = role.roleid WHERE ios_worker.username = ? LIMIT 1";
$stmt = $mysqli->prepare($sql);
$result = $stmt->bind_param('s', $username);
$result = $stmt->execute();

var_dump($mysqli);


if (!$result) {
echo $mysqli->error;
}

var_dump($result);

while ($row = $result->fetch_assoc()) { // <-- fails here
...
}



Output:



Notice: Undefined index: source in /home/infobo9/www/xxx/login.php on line 23
object(mysqli)#2 (19) { ["affected_rows"]=> int(-1) ["client_info"]=> string(6) "5.5.40" ["client_version"]=> int(50540) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(9) ["host_info"]=> string(33) "xxx via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(10) "5.5.37-log" ["server_version"]=> int(50537) ["stat"]=> string(52) "Commands out of sync; you can't run this command now" ["sqlstate"]=> string(5) "HY000" ["protocol_version"]=> int(10) ["thread_id"]=> int(82066639) ["warning_count"]=> int(0) }
bool(true)
Fatal error: Call to a member function fetch_assoc() on a non-object in /home/infobo9/www/xxx/login.php on line 41


So $mysqli is set, and $result is true. What am I doing wrong?

I also copied the query and it runs without any problems in PHPMyAdmin.



I know this answer was asked multiple times but I am not able to fix this issue since hours and none of the answers fixed my problem.

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...