Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean
You will get this error, if you call fetch_assoc() on $mysqli::result object whose value is false as shown in the below example
$result is false, thats why we are getting a Fatal Error.
<?php
// Incorrect select statement
$qry="SELECT * names";
// $result value is false
$result = $mysqli->query($qry);
// calling fetch_assoc() on $result which is (boolean) false results in fatal error
while ($row = $result->fetch_assoc()) {
print_r($row);
}
?>
[FIX] You can fix this by making sure sql statement is syntaically correct and is executed with no errors as shown in the below example.
<?php
$qry="SELECT * FROM names";
// proceed only if a query is executed
if($result = $mysqli->query($qry)){
while ($row = $result->fetch_assoc()) {
print_r($row);
}
}
?>
Still getting the error? Use comments section, I'm happy to help
ALTERNATE TITLES