Пример #1
2
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
         if (PHP_VERSION_ID >= 50600 && (!isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) || true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])) {
             $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
         }
         return $pdo;
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
 }
Пример #2
0
 /**
  * @expectedException \Doctrine\DBAL\Driver\PDOException
  */
 public function testThrowsWrappedExceptionOnPrepare()
 {
     // Emulated prepared statements have to be disabled for this test
     // so that PDO actually communicates with the database server to check the query.
     $this->driverConnection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
     $this->driverConnection->prepare('foo');
     // Some PDO adapters like PostgreSQL do not check the query server-side
     // even though emulated prepared statements are disabled,
     // so an exception is thrown only eventually.
     // Skip the test otherwise.
     $this->markTestSkipped(sprintf('The PDO adapter %s does not check the query to be prepared server-side, ' . 'so no assertions can be made.', $this->_conn->getDriver()->getName()));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
         if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES') && (!isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) || true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])) {
             $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
         }
         /* defining client_encoding via SET NAMES to avoid inconsistent DSN support
          * - the 'client_encoding' connection param only works with postgres >= 9.1
          * - passing client_encoding via the 'options' param breaks pgbouncer support
          */
         if (isset($params['charset'])) {
             $pdo->query('SET NAMES \'' . $params['charset'] . '\'');
         }
         return $pdo;
     } catch (PDOException $e) {
         throw DBALException::driverException($this, $e);
     }
 }