Questions And Answers

More Tutorials

PHP Common Errors

Call fetch_assoc on boolean

If you get an error like this:
Fatal error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\stack\index.php
on line 7

Other variations include something along the lines of:

mysql_fetch_assoc() expects parameter 1 to be resource, boolean given...

These errors mean that there is something wrong with either your query (this is a PHP/MySQL error), or your referencing. The above error was produced by the following code:

$mysqli = new mysqli("localhost", "root", "");

$query = "SELCT * FROM db"; // notice the errors here
$result = $mysqli->query($query);

$row = $result->fetch_assoc();

In order to "fix" this error, it is recommended to make mysql throw exceptions instead:
// add this at the start of the script

This will then throw an exception with this much more helpful message instead:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'SELCT * FROM db' at line 1

Another example that would produce a similar error, is where you simply just gave the wrong information to the mysql_fetch_assoc function or similar:

$john = true;
mysqli_fetch_assoc($john, $mysqli); // this makes no sense??

Unexpected $end

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\stack\index.php on line 4

If you get an error like this (or sometimes unexpected $end, depending on PHP version), you will need to make sure that you've matched up all inverted commas, all parentheses, all curly braces, all brackets, etc.

The following code produced the above error:

if (true) {
 echo "asdf";

Notice the missing curly brace. Also do note that the line number shown for this error is irrelevant - it always shows the last line of your document


In this page (written and validated by ) you learned about PHP Common Errors . What's Next? If you are interested in completing PHP tutorial, your next topic will be learning about: PHP Password Hashing Functions.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.