Call to a member function query() on a non-object

Posted by Randy Gonzalez on Stack Overflow See other posts from Stack Overflow or by Randy Gonzalez
Published on 2010-05-05T22:54:28Z Indexed on 2010/05/05 22:58 UTC
Read the original article Hit count: 238

Filed under:
|
|

Ok, this is so weird!!! I am running PHP Version 5.1.6 when I try and run the code below it gives a fatal error of an object that has not been instantiated. As soon as I un-comment this line of code //$cb_db = new cb_db(USER, PASSWORD, NAME, HOST); everything works. Even though I have declared the $cb_db object as global within in the method. Any help would be greatly appreciated.

require_once ( ROOT_CB_CLASSES . 'db.php');

$cb_db = new cb_db(USER, PASSWORD, NAME, HOST);

class cb_user {
    protected function find_by_sql( $sql ) {
        global $cb_db;

        //$cb_db = new cb_db(USER, PASSWORD, NAME, HOST);
        $result_set = $cb_db->query( $sql );

        $object_array = array();
        while( $row = $cb_db->fetch_array( $result_set ) ) {
            $object_array[] = self::instantiate( $row );
        }
        return $object_array;
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about class