In my project I have a database class that I use to handle all the MySQL stuff. It connects to a database, runs queries, catches errors and closes the connection.
Now I
Simple, 3 step process. 1/ Create a database object. 2/ Give it to your user class constructor. 3/ Use it in the user methods.
Little example.
File Database.class.php :
In User.class.php :
_db = $db;
}
public function deleteUser(){
$this->_db->query('DELETE FROM Users WHERE name = "Bobby"');
}
}
Now, in userManager.php for example :
deleteUser();
If you want the current trendy name of this old technique, google "Dependency Injection". The Singleton pattern in php will fade away soon.