MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 11th, 2005, 01:59 AM
rlocke rlocke is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 rlocke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 26 sec
Reputation Power: 0
supplied argument is not a valid MySQL result resource

Greetings,

I have a problem which shows up *intermittently* when executing a simple query. Basically, mysql_query() returns no resource *some* of the time:

"PHP Warning: mysql_num_rows(): supplied argument is not a
valid MySQL result resource in /home/www/..."

When I trap the error using mysql_error(), I get the following:
"No Database Selected"

For kicks, I altered the query to use the fully qualified table name (<db>.<table>), and the error changed to:
"Access denied for user: 'username@%' to database 'db'"

I was able to replicate this on a browser as well as using "ab" with no concurrency. The system will sometimes handle 1000 or more queries without any problems, and then a bunch of errors will appear.

I cannot roll this out into a production environment until this is fixed. I would really appreciate any advice.

Here's the relevant code:

$conn = mysql_connect(CHAR_DB,CHAR_DB_USER,CHAR_DB_PASS) or die("Cannot connect to db.");

mysql_select_db(USER_DB, $conn);

$sql = "SELECT cash FROM cash WHERE id = '$id'";

$res = mysql_query($sql);

if (!$res) {
error_log('Invalid query: ' . mysql_error());
}

$numrows = mysql_num_rows($res);

Thanks!

Reply With Quote
  #2  
Old March 11th, 2005, 07:48 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
A simple debugging technique...

Add this to your code:
$res = mysql_query($sql) or die("Error ".mysql_errno().": ".mysql_error()."<br>\nThe SQL sent was: $sql");



Refer to the PHP documentation if you are unsure of what these functions do:

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > supplied argument is not a valid MySQL result resource


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway