SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: "not a valid MySQL result resource" in plain English

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    "not a valid MySQL result resource" in plain English

    Can you tell me if I got this right? In plain English, "not a valid MySQL result resource" means, "I can't execute this line of code because something else is missing or wrong." That's kind of vague. Can it be made more specific?

    Thanks!

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    yes, it can be much more specific

    run it outside of php
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am not talking about a specific case, but trying to understand the warning in my head.

  4. #4
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    well, to begin with, it's a php error message

    it is telling you that something is wrong with your mysql query, that it did not return a resource

    i'm not really sure how it works, because i don't do php

    and this is the mysql forum

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That tells you how ignorant I am! I thought it had to do with queries, so this was the right place for the question.

  6. #6
    reads the ********* Crier silver trophybronze trophy SitePoint Award Recipient longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the mysql_query() function returns a "resource" that holds the result of the query. expect that if the query results in an error, mysql_query() returns a boolean FALSE.

    so let's say you have some code like this:
    PHP Code:
    $result mysql_query('select * form test_table');
    $first_row mysql_fetch_assoc($result); 
    this query will obviously fail because i mis-spelled FROM as FORM. $result will therefore be a boolean FALSE. mysql_fetch_assoc() expects its first parameter to be a valid mysql resource. this is obviously not the case, hence the error.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  7. #7
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That makes the terminology a little clearer. So far I have: The resource is the variable name we give for the query's result. The result is the contents of the resource, which result is generated erroneously by the query.

    What's your explanation of the "supplied argument" in the error message?

    Thanks!

  8. #8
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by StevenHu View Post
    What's your explanation of the "supplied argument" in the error message?
    the supplied argument is the query

    it didn't work (produce a result resource)

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Now it all comes together!

    Sometimes I've seen this error on a WHILE statement, so it may cast a broader net.

  10. #10
    SitePoint Zealot
    Join Date
    Aug 2008
    Location
    NC
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll see this errors in lots of situations. Basically a mysql query returns an object, the "resource", you have to then use something like mysql_fetch_assoc() to parse the "resource" object into something that you can use. So whenever you see an error that mentions an invalid resource, that means either you didn't get a valid object, or php can't parse the object for some reason.

  11. #11
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can also troubleshoot your SQL with a PHP error by using die(mysql_error());

    PHP Code:
    $sql "QUERY";
    $result mysql_query($sql) or die(mysql_error()); 
    No, I REALLY dislike having to use Joomla.

  12. #12
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Crowden: Yes, I'm trying to use the troubleshooting as soon as I get an error. I've been reminded of this often enough on this blog!

    Ditch182: Thanks, that was helpful.

  13. #13
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,849
    Mentioned
    16 Post(s)
    Tagged
    1 Thread(s)
    It generally means your sql statement is incorrect.

    Most often this is caused by a variable coming from PHP that didn't behave as expected.

    $sql ="select thing from things where thing = '$some_thing' ";

    The sample that crowden supplied:
    PHP Code:
    $sql "QUERY";
    $result mysql_query($sql) or die(mysql_error()); 
    ... illustrates a good practice, because a) it obviously displays some kind of error ( which you may not want on your live site ) but b) it gives you the opportunity to echo out $sql onto the page or log it.

    Whereas this:
    PHP Code:

    $result 
    mysql_query($sql ="select thing from things where thing = '$some_thing' ";) or die(mysql_error()); 
    .. does not give you that opportunity.

    There are lots of way of getting the sql into the light, but its probably generally true that many errors like this can be a mixture of PHP and sql errors.

    Anyhow, get used to seeing them and work out a way of dealing with them because they will happen to you all the time, that way you hone in on where the error is coming from.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •