/** * Create new DB instance. */ public function __construct() { if (!self::$dbh) { parent::__construct(); $db_string = 'dbname=' . $this->dbname; $dsn = 'mysql:host=' . $this->host . ';' . $db_string; try { self::$dbh = new PDO($dsn, $this->user, $this->pass); self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } }