dbh = new PDO('mysql:host=localhost;dbname=people', '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 $dbh; public function __construct($db_handle) { $this->dbh = $db_handle; } public function showPersons() { $sql = "SELECT * FROM person"; $result = $this->dbh->query($sql); foreach ($result as $row) { echo $row['first_name']." ".$row['last_name']."
"; } } } $db_handle = DBConnect::getInstance(); $person = new Person($db_handle); $person->showPersons(); ?>