/** * {@inheritDoc} */ public function connect() { parent::connect(); // For debugging and sanity, make PDO report any problems, not fail silently $this->pdoObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); if (!$this->isInit()) { $this->init(); // Init the database if required } }
/** * {@inheritDoc} * * @throws \Exception When database cannot be connected to */ public function connect() { parent::connect(); // For debugging and sanity, make PDO report any problems, not fail silently $this->pdoObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); try { $this->pdoObject->exec('USE ' . $this->dbName); } catch (\PDOException $e) { throw new \Exception('Failed to access database named ' . $this->dbName . ' // ' . $e->getMessage()); } if (!$this->isInit()) { $this->init(); // Init the database if required } }