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