You'll learn how to identify the failed MySQL query behind the "expects parameter 1 to be resource" warning and fix it using modern, reliable PHP database code.
Time needed: Approximately 10–20 minutes.
If you're maintaining an older PHP application, you may encounter an error like this:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given
Enter fullscreen mode
Exit fullscreen mode
The same warning can appear with several functions:
mysql_fetch_assoc() expects parameter 1 to be resource mysql_fetch_row() expects parameter 1 to be resource mysql_num_rows() expects parameter 1 to be resource
Enter fullscreen mode
Exit fullscreen mode
These warnings usually have one underlying cause: the SQL query failed, but the application tried to read its result anyway.
The fetch function is where the problem becomes visible.…