Terrible Error while using MySQL resources

Reply

Join Date: Jul 2005
Posts: 2
Reputation: SpittingSctsman is an unknown quantity at this point 
Solved Threads: 0
SpittingSctsman SpittingSctsman is offline Offline
Newbie Poster

Terrible Error while using MySQL resources

 
0
  #1
Jul 21st, 2005
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in _____________________________________________________

I have seen a lot of this around the internet lately, both in forums and on some production websites (WHOOPS!) :cheesy: I am currently developing a small site which uses MySQL as it's data repository, and I am encountering this error at random. It seems to me like it occures mostly when something was mispelled in an sql query or when a variable has a type-mismatch.

In any event, I think the reason why this is happening is because I am using a wrapper class for the my_sql resources. This just makes things easier to manage if you ask me, however, the lines of code that Zend is pointing to are:

$this->result = mysql_query($sql);
$this->numberofRows = mysql_num_rows($this->result);


I think that it may be because it doesn't recognize $this->result as a valid resource, since $result seems to work.

Does anyone know one SURE way to resolve this issue, or is it different all the time?
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Terrible Error while using MySQL resources

 
0
  #2
Jul 21st, 2005
I doubt the errors are random. It is caused by something, usually human error, 99.9% of the time

I'm not too sure with your code, but be assured that the error is trying to make as much sense as possible, in this case. That's the best I can say for now.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

supplied argument is not a valid MySQL result resource

 
0
  #3
Jul 21st, 2005
PLEASE read my post in this thread:
http://www.daniweb.com/techtalkforum...n+newbies.html
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 2
Reputation: SpittingSctsman is an unknown quantity at this point 
Solved Threads: 0
SpittingSctsman SpittingSctsman is offline Offline
Newbie Poster

Re: Terrible Error while using MySQL resources

 
0
  #4
Jul 22nd, 2005
HAHA! OMG. I got it guys. Akh. Thanks for the tips. I found out (by poking around my code) that this error is always the result of a MySQL resource being NULL or of the wrong type. It occured to me that php uses generic variables, which means that if mysql doesn't return a My_SQL resource, it is impossible for the variable $result to be initialized and as such is considered a type mismatch by MySQL.

So, this means that any time MySQL doesn't return a value, such as a query result, you will get this error message.

There are basically three common occurences of this that I have experienced:

I am trying to catch the result of an sql query that attempts to do something other than SELECT.

When I have a query that fails due to improper syntax, or typo's in the tablename or column names.

When the database connection has not been properly initialized, i.e mysql_connect, and or my_sql_select_db have not been called for some reason...

in this particular instance, I forgot parenthesis after calling $db->SelectDB();
:o
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC