dbh = new PDO('mysql:host=localhost;dbname=petcatalog', 'root', ''); } catch (PDOException $e) { echo $e->getMessage(); } } public static function getInstance() { if (!isset(DBConnect::$db)) { DBConnect::$db = new DBConnect(); } return DBConnect::$db->dbh; } } class Person { public function __construct() { global $db_handle; } public function showPersons() { global $db_handle; $sql = "SELECT * FROM person"; $result = $db_handle->query($sql); foreach ($result as $row) { echo $row['first_name']." ".$row['last_name']."
"; } } } $db_handle = DBConnect::getInstance(); $person = new Person($db_handle); $person->showPersons(); ?>