I already have a database file that connects to a database when I include it
class-database.php
class dbFactory {
private static $host = 'some.host.com';
private static $name = 'someDB';
private static $user = 'someUser';
private static $pass = 'somePassword';
public function __construct() { }
public static function pdo() {
try {
# MySQL with PDO_MYSQL
return new PDO("mysql:host=$host;dbname=$name", $user, $pass);
}
catch(PDOException $e) {
echo $e->getMessage();
return null;
exit;
}
} // End: pdo()
} //End class
I usually access this by:
require( 'some-file-path' . 'class-database.php' );
$db = dbFactory::pdo();
Here is the question:
How can I access $db
from within another class?
For instance, if I have a class file called class-html.php
and within that class (AKA, as part of the class code) I need something like...:
class-html.php
class html {
...some code...
$db->query('SELECT * FROM tbl_head');
...some more code...
} //End: html
What I've been doing without success is:
require( 'some-file-path' . 'class-database.php' );
$db = dbFactory::pdo();
require( 'some-file-path' . 'class-html.php' );
I am getting error messages and am not sure what to do from here