Call to undefined method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead
Forum Newbie
Posts: 14
Joined: Sat Oct 13, 2012 11:51 am

Call to undefined method

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Call to undefined method

Post 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)
Post Reply