mysql_fetch_array() expects parameter 1 to be resource, boolean given

MySQL Best Practices

Trying to select data from a MySQL table, but getting the error messages:

mysql_fetch_array() expects parameter 1 to be resource, boolean given?

– This may happen for various reasons like both the mysql_* and the mysqli extension will return false from their query functions.

– Using a die() you can get a little to much.

– Use mysql_error() which reports any errors that MySQL encountered while performing the query.

– If you have a syntax error in your query you can check with tools like phpMyAdmin.

– A missing quote around the mysql query or a value can cause a failure.

– Do not mix mysqli_* and mysql_* functions.

– Make sure you are escaping your all values.

Leave a Reply

Your email address will not be published. Required fields are marked *

seven − two =