The Web Blinders logo

Programming

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean

Fatal error: Uncaught Error: Call to a member function fetch_assoc()

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

Error: Call to a member function fetch_assoc() on boolean in

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on

fetch_assoc() not working php mysql

php mysql tutorials

Php tutorials

fetch_assoc() example

fetch all rows php mysql

fetch row by row php mysql

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES