mysql_num_rows() problem… a solution

February 20, 2009 – 11:20 am

I know this is a internet blog rather than a coders blog, but after a while of seeing this problem and not finding any help with it I thought I would post here about some success I had.

Over the last few months I have had a few sites come up with this problem:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in/dir/page.php line 123

The problem is that the problem seemed intermittent with no similarity or some thread I could link to another.

Most it was about getting numbers of rows of records for paginating database results.

Yesterday, I had a similar problem with a third party product which I had purchased on behalf of a client and lodged a ticket.

I got a quick response that this was an issue with the version we were running and MySQL 5

In this case it seems that a reserved word was used in the database for one of the column names and when this was used in the database queries, it failed giving the above error.

After a few code replaces it worked great.

Big thanks to the support team for their quick response.

However, here are the things learnt from this:

  1. Reserved words are a bit of a pain as version 5 of MySQL added some more that were plain language (this one was the word “out”
  2. The error mentioned above is a failure of the query to generate a valid result, not that the result is empty.
  3. Running the query in phpmyAdmin or similar can shed extra light into what is failing

The MySQL reserved words can be found here

So endeth the coders rant, normal service now resumes :-)

Let me know if you have any similar issues

  1. 2 Responses to “mysql_num_rows() problem… a solution”

  2. Put backticks around the column name?

    By Tim on Feb 20, 2009

  3. Hi there,

    From my reading, there are a few ways to get around it in certain circumstances, not sure if the backtick would work as you are working with the structure of the database rather than the data. Have you tried it?

    Cheers

    By Webmaster on Feb 20, 2009

Post a Comment


Home | Portfolio | Services | Request Quote | Hosting | Domain Names | About Deepweb | Contact Us
© Deepweb Web Design   Our Privacy Policy
Deepweb is proudly powered by WordPress Entries (RSS) and Comments (RSS). Designed by Bob

Bad Behavior has blocked 166 access attempts in the last 7 days.