PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; try { $this->conn = new PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { // In a real app, you'd log this error and show a generic message throw new \PDOException($e->getMessage(), (int)$e->getCode()); } } public static function getInstance() { if (self::$instance == null) { self::$instance = new Database(); } return self::$instance; } public function getConnection() { return $this->conn; } // Prevent cloning and unserialization private function __clone() { } public function __wakeup() { } }