/** * 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()); } $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL); $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler); }
/** * Connect with PDO * * @return null */ private function connect() { // Connecting with PDO try { switch ($this->dbType) { case 'sqlite': $this->dbHandler = @new PDO("sqlite:" . $this->db, null, null, $this->pdoSettings); break; case 'mysql': case 'pgsql': case 'dblib': $dsn = $this->dbType . ":host=" . $this->host . (isset($this->port) ? ";port=" . $this->port : "") . ";dbname=" . $this->db; $this->dbHandler = @new PDO($dsn, $this->user, $this->pass, $this->pdoSettings); // Fix for always-unicode output $this->dbHandler->exec("SET NAMES " . $this->dumpSettings['default-character-set']); // 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()); } $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL); $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler); }