mysql_num_rows Error. Suplied argument is not a valid MySQL resource.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpenney
    New Member
    • Sep 2007
    • 7

    mysql_num_rows Error. Suplied argument is not a valid MySQL resource.

    Hi,

    I gotta dum kweschin.

    Here's muh code:
    [code=php]
    class dbServer{
    ...
    public function &executeDBCOMMA ND($SQL=";"){

    $result = mysql_query($SQ L);

    }

    public function connect(){
    echo 'Connecting to server ' . $this->servername . '<br>';
    $this->dbconnection = mysql_connect($ this->servername,$th is->username,$th is->password);
    if(!$this->dbconnection ){
    throw new Exception("did not connect");
    }
    return true;
    }

    ...
    }


    $s=$d=$t="x";

    $s = new dbServer("local host","__MUNGED __","__MUNGED__ ") or die ("no dbserver");
    if($s<>'x') $s->connect() or die ("no dbserver");

    if($s<>'x') $d = new dbDatabase("__M UNGED__") or die ("no database");
    if($d<>'x') $d->connect() or die ("no database");

    if($d<>'x') $t = new dbTable("Table1 ") or die("no table");

    if($t<>'x')
    {
    try{
    $result =& $s->executeDBCOMMA ND("show tables;");


    ///////////////////////////////////////////////////////////////
    //LINE 184 (where the error is)
    ///////////////////////////////////////////////////////////////
    $num=mysql_numr ows($result) or die('<hr />MySQL Error: '
    .mysql_error(). '<hr />');
    ///////////////////////////////////////////////////////////////

    ...
    }
    catch{...}
    ...
    }
    ?>
    [/code]
    So when I run it, I get the following error:

    Warning: mysql_numrows() : supplied argument is not a valid MySQL result resource in /nfsexport/var/www/doc_root/info/no-ip/yourwebsite/jpenney/phpfiles/fieldlib.php on line 184

    I think it's a problem with returning the reference, but I'm not sure. Any hints?

    Thanks,

    JP
    Last edited by Atli; Sep 8 '07, 05:47 PM. Reason: Added [code] tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi JP, and welcome to TSDN!

    I've changed the title of this thread to better describe it's topic.
    Using good, descriptive titles that follow the Posting Guidelines will increase your chances of getting your questions answered!

    Also, remember to use [code] tags when posting code. It is nearly impossible to read it without them.

    Moderator

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      What this means is that the $result your database object is returning to you is not a valid MySQL resource.
      The most common reason for this is invalid queries. If you query fails the mysql_query() function will return FALSE, which is not a valid MySQL resource.

      You should always check if the $result returned by a query is valid before trying to use it.

      Also, in the executeDBCOMMAN D method, you should include the dbconnection as a second parameter in the mysql_query() function.

      P.S. executeDBCOMMAN D is a horrible method name :)

      Comment

      • Weisbartb
        New Member
        • Aug 2007
        • 36

        #4
        Don't return by reference in a function especially in an object(PHP online docs tell you specifically not to do it.). Change your code to return $result in your execute method. And don't assign it by reference. You are currently attempting to get the rows of a reference not a MySQL ID.

        Comment

        • jpenney
          New Member
          • Sep 2007
          • 7

          #5
          Thank you all for your help. I guess I need to hit the books a little more.

          JP

          Comment

          Working...