This article mainly introduces the php prompt Warning: mysql_fetch_array () expects solution. It is a typical case of php program error troubleshooting and has some reference value, for more information, see
This article mainly introduces the php prompt Warning: mysql_fetch_array () expects solution. It is a typical case of php program error troubleshooting and has some reference value, for more information, see
The example in this article describes the solution of the php prompt "Warning mysql_fetch_array () expects", which is for your reference. The specific analysis is as follows:
When connecting to the mysql database, the following error occurs: Warning: mysql_fetch_array () expects.... In my experience, the query returned by the SQL statement is empty. We have not used it directly.
Mysql_fetch_array () function. Let's take a look at the problem solution. My code is as follows:
The Code is as follows:
Include ("conn. php ");
If (! Empty ($ _ GET ['id']) {
$ SQL = "select * from news where 'id' = '". $ _ GET ['id']. "'";
$ Query = mysql_query ($ SQL );
$ Rs = mysql_fetch_array ($ query );
}
Error message: Warning: mysql_fetch_array () expects parameter 1 to be resource, boolean given in F: xmappmylibrarysearch_result.php on line 32
Later, I upgraded the Code as follows:
The Code is as follows:
If (! Empty ($ _ GET ['id']) {
$ SQL = "select * from news where 'id' = '". $ _ GET ['id']. "'";
$ Query = mysql_query ($ SQL );
If (mysql_num_rows ($ query)
{
$ Rs = mysql_fetch_array ($ query );
}
Else
{
Mysql_error ();
}
}
In this way, the mysql error message is displayed. The result is that the SQL statement is faulty. Modify the SQL statement.
Tip: This type of error occurs because our syntax is not standard. If you want to handle this type of error, you can only output one SQL statement or process it in mysql_query (SQL) or die (mysql_error ,, to locate errors more accurately.
I hope this article will help you with PHP programming.