db = $this->getConnection(); } private function getConnection() { static $connection = null; if ($connection === null) { $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8'; try { $connection = new PDO($dsn, DB_USER, DB_PASS); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die('DB connection error: ' . $e->getMessage()); } } return $connection; } }