mysql_num_rows(): supplied argument is not a valid MySQL result resource
Posted by: Steve Stout
Date: February 23, 2006 05:55PM
I have been programming MySQL with PHP for many years now, and I have been getting the error message of:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\blahblah.php on line 130.
This query works most of the time, but sometimes it produces the error message without me changing any code. ISP is not changing anything. It is random and does not seem to happen at just peak traffic times. I think they even got me on my own MySQL server right now.
PHP Version = 4.3.10
Server Software = Microsoft-IIS/6.0
I have searched these forums and see where several others have posted the same issues of an intermittent problem but none of these posts have had a reply that answers why.
I have had this error pop up when a SQL query was incorrect, this is not the case. If my SQL query was incorrect, it would give the error message every time. Not randomly.
It has been suggested that this is due most times to failing to connect to the database. I find this hard to believe in my situation as it always happend at the same place in the code, which is usually the largest table being queried in the php script. The queries before and after work fine. Today I have had this happen on a query of 3000 rows, and one of 20000 rows. It never happens on the smaller tables in my database. Seems to happen only on tables over 2000 rows? It only happens on my largest tables, never on a small one.
I see where someone else has put in code to try to get more of an error message from the MySQL server, but they didn't get anything that helped. I have done this today, but am not holding my breath for enlightenment from it.
20000 row query:
$query = "
WHERE R_TimeStamp > '$StartDate'
AND R_TimeStamp < '$EndDate'
3000 row query:
$query = "
WHERE P_Active = 1
(tried the above query with P_Active = '1' but no change)
These queries work 95%+ of the time just fine, but sometimes it starts giving the error for one page load, or for up to an hour. Then it goes away and the query works fine for days. (Or at least I don't notice it for days!)
This just seems to be a bug which should be fixed. If not, then what is it? I have not seen an answer to this question yet, even though it has been posted and asked many times now, for almost a year.