| | |
Terrible Error while using MySQL resources
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
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?
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?
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.

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.
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Another mysql problem (JSP)
- about VC+MySQL problem:) (C)
- I need hosting (Web Hosting Deals)
- can't install Apache-many tries (Linux Servers and Apache)
- Error with Update (MySQL)
- installing php and mysql properly (Windows Servers and IIS)
- Error message when trying to run an .exe file from the desktop (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: WMServer tools issue
- Next Thread: How do I create own Shout box/or input and display form?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop parse paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





