Php error prompt: mysql_fetch_row (): suppliedargumentisnotavalidMySQL tests the database connection Today. the following error occurs when the information in the data table is traversed:
Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in D: \ AppServ \ www \ wordpress \ lianjie001.php on line 20
The original code I wrote is as follows:
$ Db_host = "localhost ";
$ Db_database = "wordpress ";
$ Db_username = "root ";
$ Db_password = "admin123 ";
$ Connection = mysql_connect ($ db_host, $ db_username, $ db_password );
Mysql_query ("set names 'utf8 '");
$ SQL = "select * from huanzhexinxi ";
$ Result = mysql_query ($ SQL );
While ($ resultrowzhen = mysql_fetch_row ($ result ))){
$ Huanname = $ resultrowzhen [0];
$ Huanage = $ resultrowzhen [1];
$ Huancall = $ resultrowzhen [2];
$ Huanliu = $ resultrowzhen [3];
Echo"";
Echo"Name: $ huanname
";
Echo"Age: $ huanage
";
Echo"Tel: $ huancall
";
Echo"Patient message: $ huanliu
";
Echo"
";
}
Mysql_close ($ connection );
?>
After half a day of check, no error was found. my colleague pointed out that the database selection code was missing, as shown below:
$ Db_selecct = mysql_select_db ($ db_database );
The complete code is as follows.
$ Db_host = "localhost ";
$ Db_database = "wordpress ";
$ Db_username = "root ";
$ Db_password = "admin123 ";
$ Connection = mysql_connect ($ db_host, $ db_username, $ db_password );
Mysql_query ("set names 'utf8 '");
$ Db_selecct = mysql_select_db ($ db_database );
$ SQL = "select * from huanzhexinxi ";
$ Result = mysql_query ($ SQL );
While ($ resultrowzhen = mysql_fetch_row ($ result ))){
$ Huanname = $ resultrowzhen [0];
$ Huanage = $ resultrowzhen [1];
$ Huancall = $ resultrowzhen [2];
$ Huanliu = $ resultrowzhen [3];
Echo"";
Echo"Name: $ huanname
";
Echo"Age: $ huanage
";
Echo"Tel: $ huancall
";
Echo"Patient message: $ huanliu
";
Echo"
";
}
Mysql_close ($ connection );
?>
Reply to discussion (solution)
Are you sure you want to ask? Or do you want to share your experience?
The closing rate is 0. it is estimated that it was just a whim.
It is better to teach people to fish than to teach them to fish.
Echo mysql_error ();
Mysql_query ($ SQL) or die (mysql_error ());
Solution on the 4th floor .........