Page 1 of 1

Call to a member function query_db() on a non-object?

Posted: Mon Dec 21, 2009 12:39 pm
by scatty1985
Hi,

Im getting the error Call to a member function query_db() on a non-object on the following line of code.

Code: Select all

$db->query_db($q);
From function:

Code: Select all

function e_Check($e) {
        $q = "SELECT email FROM users WHERE email='$e'";
        $db->query_db($q);
        return ($db->q_rows($db->q_result) < 1);
    }
The code from the class is:

Code: Select all

// Query database
    function query_db($query_string) {
        $this->q_result = mysql_query($query_string);
    }
I cant work out why, cant any one give me some advice?

Re: Call to a member function query_db() on a non-object?

Posted: Mon Dec 21, 2009 12:48 pm
by Darhazer
$db is not defined in the function.
You have to instantiate your class.
Or if this is a global object, use

Code: Select all

global $db;
before using the variable. However, using global objects is not a good practice.

Re: Call to a member function query_db() on a non-object?

Posted: Mon Dec 21, 2009 12:51 pm
by scatty1985
Ah I understand...

Code: Select all

function e_Check($e,&$db) {
Instead ;-)