PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

PHP FAQ: What is the PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in error message, and how do I fix it?

I just ran into this this "mysql_fetch_array() expects parameter 1 to be resource, boolean given" error message, and learned that it's because there's something wrong with my SQL query.

While I'm still learning PHP, I learned this by (a) looking at my PHP log file, (b) doing a var_dump on my query, (c) then testing that query directly in MySQL, where I learned I had written some part of my SQL query incorrectly.

So, the solution to the "mysql_fetch_array() expects parameter 1 to be resource, boolean given" PHP error message is to fix your query.

Handle your PHP SQL errors properly

That being said, you can also find this problem much more easily by catching your PHP SQL query errors more easily, specifically with this PHP error handling syntax:

$result = mysql_query($query);
if (!$result)
{
  error_log("Error in query ($query): " . mysql_error());
  # now handle this php error in your app
}

In this example the variable $query contains the SQL query you're trying to run.

mysql_fetch_array expects parameter 1 to be resource, boolean given in - summary

I hope this "mysql_fetch_array() expects parameter 1 to be resource, boolean given in" discussion has been helpful. Remember, (1) the problem is with your SQL query, and (2) you should always test the results of your SQL query as shown here.