L
L
LissaAlbatross2020-05-22 22:28:30
PHP
LissaAlbatross, 2020-05-22 22:28:30

Fatal error: Call to a member function fetch_array() on a non-object in MySQL?

$query = "SELECT * from  table";
$result = $mysqli->query($query);
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
…
}

I repeat the same code (but with a different select) in a file that is called via ajax (I connect to the database in a new way) and I get the error Fatal error: Call to a member function fetch_array() on a non-object in . What can be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-05-23
@FanatPHP

For the future, the next line should always be in the file with the database connection

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

And then this error will never appear at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question