This is a note on an error that I have gotten several times when writing php scripts with mySQL.
The error is:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
The offending code snippet essentially looks like this:
$result = mysql_query(“$query_STRING” );
if (mysql_num_rows($result) > 0)
{which then continues on…
Note that $query_STRING is a string variable that contains the mySQL query.
The problem with this error message is that it is typically due to a problem in the query itself, and there can be many causes. To catch the cause, change the line that performs the query to:
$result = mysql_query(“$query_STRING” ) or die(mysql_error());
The statement die(mysql_error()) will catch the true error and with luck give you a more meaningful error message.
Posted under Programming, Software
This post was written by drknuth on January 31, 2009



