suplied argument not valid mysql sql resource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bilibytes
    New Member
    • Jun 2008
    • 128

    suplied argument not valid mysql sql resource

    hi,
    i tried to create sort of a db abstraction layer in order to be able to change of database (Mysql | oracle | pg |...).

    i implemented that on a obejct oriented way.

    i made a sql factory in PHP which simply instanciate classes whose methods wrap the php normal sql functions like mysql_query() mysql_num_rows( ) pg_query()...
    one of these methods is num_rows()

    i implemented it this way:
    Code:
    public function num_rows($result)
    {
        return mysql_num_rows($result);
    }
    the problem is it will generate a mysql error:
    mysql_num_rows( ): supplied argument is not a valid MySQL result resource in ...

    so i thought it could be because i'm not passing the argument as a reference so i changed that to:

    Code:
    public function num_rows(&$result)
    {
        return mysql_num_rows($result);
    }
    but it still returns that error.

    how should that be done?

    do you have any suggestions?

    by the way how can i know if an insertion succeed, without the "or die(mysql_error )"?

    please let me know

    thank you!

    best regards

    bilibytes
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Echo out the value of $result.
    It should be something like #2.
    If not, as is almost certainly the case the result resource is not in $result.
    We would need to see more code to repair this.

    Also a reminder this only works with SELECT queries

    On a design point I have a similar class.
    But because the result resource may be used within a number of methods
    I place it in a class member variable

    //Private members
    private $result;

    function xxxxxx()
    $this->result = mysql_query()

    function xxx()
    mysql_num_rows( $this->result)

    Comment

    • bilibytes
      New Member
      • Jun 2008
      • 128

      #3
      Thank you for your time.

      but i managed to solve it, it was a problem of the mysql_query() wrapper.

      Code:
      public function query($sql_code)
      {
          return mysql_query($sql_code, $this->link) or die(mysql_error());
      }
      i put the or die(mysql_error ()) while debugging and that was causing all the problems.
      What i still don't understand is why it happens.. what does it return when i put or die(mysql_error ())
      mysql_error() should not get triggered as when i don't put the or die()... the query works perfectly.

      ahhh maybe it returns a boolean?

      like: "return the evaluation of these two conditions, if one is true retrun true?"

      i think that may be the reason

      best regards

      Comment

      Working...