I am fairly new to using objects in php. I have made a fairly simple database object so i can just call one of a few of my own methods to automatically make changes to the database when i change the relevant object. Below is a very simplified version of what i am trying to accomplish:
Class Database{
public function Query($query){
//connect to database, run query and return result
}
}
Class User{
private $username;
private $db;
public function __construct($intID){
$this->db = new Database();
if($intID > 0){
getUserData($intID);
}
}
public function getUserData($intID){
$sql = "select * from users where intID = $intID";
return $this->db->Query($sql);
}
}
The problem i get is when "$this->db->Query($sql);" is executed and the error i get is:
"Fatal error: Call to a member function Query() on a non-object"
According to the IDE i am using, the function is accessible, but it seems when running the code, the parser cannot see that $this->db is an object with functions.
My question is, is what i am attempting to do possible or am I missing something very basic to make this work?
Thanks