/** * Performs lazy connection, only connecting to the DB when a query is actually performed * Also ensures that only 1 connection can be active, by returning the existing PDO object if one exists * @return <type> */ public function lazyConnect() { if (!self::$_dbh instanceof \PDO) { try { self::$_dbh = new \PDO($this->_dsn, $this->_dbinfo['username'], $this->_dbinfo['password']); self::$_dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (\PDOException $e) { die('Could not connect to database'); } } return self::$_dbh; }