/** * Connect with PDO * * @return null */ private function connect() { $this->dbHandler->query("SET NAMES " . $this->dumpSettings['default-character-set']); $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler); }
/** * Connect with PDO * * @return bool */ private function connect() { // Connecting with PDO try { switch ($this->_dbType) { case 'sqlite': $this->_dbHandler = new PDO("sqlite:" . $this->db, null, null, $this->_pdoOptions); break; case 'mysql': case 'pgsql': case 'dblib': $this->_dbHandler = new PDO($this->_dbType . ":host=" . $this->host . ";dbname=" . $this->db, $this->user, $this->pass, $this->_pdoOptions); // Fix for always-unicode output $this->_dbHandler->exec("SET NAMES utf8"); break; default: throw new Exception("Unsupported database type (" . $this->_dbType . ")", 3); } } catch (PDOException $e) { throw new Exception("Connection to " . $this->_dbType . " failed with message: " . $e->getMessage(), 3); } $this->_dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL); $this->_typeAdapter = TypeAdapterFactory::create($this->_dbType); }
/** * Connect with PDO * * @return null */ private function connect() { // Connecting with PDO try { switch ($this->dbType) { case 'sqlite': $this->dbHandler = @new PDO("sqlite:" . $this->dbName, null, null, $this->pdoSettings); break; case 'mysql': case 'pgsql': case 'dblib': $this->dbHandler = @new PDO($this->dsn, $this->user, $this->pass, $this->pdoSettings); // Execute init commands once connected foreach ($this->dumpSettings['init_commands'] as $stmt) { $this->dbHandler->exec($stmt); } // Store server version $this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION); break; default: throw new Exception("Unsupported database type (" . $this->dbType . ")"); } } catch (PDOException $e) { throw new Exception("Connection to " . $this->dbType . " failed with message: " . $e->getMessage()); } if (is_null($this->dbHandler)) { throw new Exception("Connection to " . $this->dbType . "failed"); } $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL); $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler); }