Forum Moderators: coopster

Message Too Old, No Replies

not a valid MySQL result resource error?

I don't understand this error message...

         

meingalls

3:02 pm on May 26, 2004 (gmt 0)

10+ Year Member



On certain queries, I get the error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

This only occurs when there is a lot of data being returned. I believe it only happens when there are a lot of rows. I have trimmed down the amount of data for each row, but I still get the message at times.

I have looked at the result resource when it succeeds and when it fails. When it succeeds, the result resource is "#25", or some similar string, such as "#27". When it fails, it is also "#27". So I do not understand what is going on. I had the same error when I tried mysql_num_rows under the same circumstances.

Any suggestions?

Thank you very much,

Mel

coopster

3:18 pm on May 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, meingalls!

It is more than likely your query statement is in error. Try to get the error like so...

$result = mysql_query("SELECT * FROM table") or die (mysql_error());

if your query errors out, that will return the actual error from mysql and display it to the screen and kill the script. It helps when trying to debug queries. More tips can be found in the PHP Troubleshooting tips thread in the PHP Library [webmasterworld.com].

meingalls

3:49 pm on May 26, 2004 (gmt 0)

10+ Year Member



I am doing as you suggest. The query succeeds, and I test mysql_error() immediately after. It is blank. But when I try to use mysql_fetch_array or mysql_num_rows, I get this error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

The table I am going after has more than 300 fields, of which most are ints, 1-character flags and dates. There are 46 varchar fields and 10 blobs. Does that help?

timster

3:54 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've gotten that error sometimes when I do more than one query per page. Is that your situation?

Are you supplying myql_fetch_array() and argument, like so?

$result1 = mysql_query("SELECT * FROM table") or die (mysql_error());
mysql_fetch_array($result1);

meingalls

4:03 pm on May 26, 2004 (gmt 0)

10+ Year Member



No. There is only one query. Nothing embedded. I do the query, check the result, and if it looks good, I fetch the row. It does look good ("#27"), but the fetch fails. Could it be that I have too many fields in my table?

coopster

2:26 pm on May 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How are you establishing your connection and running your query? Something like...
$link = mysql_connect('server', 'user', 'password') 
or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error());
$db = mysql_select_db('database', $link)
or exit('Could not select database (' . mysql_errno() . '): ' . mysql_error());
$sql = "SELECT * FROM table"; // query statement
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) { // Fail here? Query statement may be bad.
while ($row = mysql_fetch_array($result)) {
// process result set
}
} else {
exit('No records returned');
}
You said this script only runs the mysql_query() function once, can you confirm that as well?

jamesa

9:50 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The query probably produced no results. The if statement coopster posted above would catch that.