Page 1 of 1

Call to undefined method

Posted: Sat Oct 13, 2012 11:56 am
by pinehead
I have two classes, one is my db.class.php which contains all of my sql functions.
When i instaniate the class with $db instead doing it over and over and over i want to pass the object into the new class.

$db = new mysql()
$account = new account($db)

So i pass $db into the class account which looks like this..

Code: Select all

	
function account($db) {
	
    $this->db = $db;
var_dump($this->db); //This actually displays the correct information and class_exists verifies the class does exist



	}
		
    function resetPassword($email) {
			$sql = $this->db->query("select * from users");
	}	
}


But when i call ->query which is a method inside of the db.class.php (and works when i don't pass the object into a new class) the error message i get is

PHP Fatal error: Call to a member function query() on a non-object in account.class.php on line 9

Any thouhts?

Thanks,

Anthony

Re: Call to undefined method

Posted: Sat Oct 13, 2012 12:23 pm
by twinedev
My thought is would need the code for both classed and the actual code you are calling to generate the error. You are not showing any code where it is trying to use the function query() which is the error (or even showing us the code for that function)