Example #1
0
 /**
  * Retrieve a database connection attribute.
  * It is necessary to override PDO's method as some MSSQL PDO driver (e.g. dblib) does not
  * support getting attributes
  * @param integer $attribute One of the PDO::ATTR_* constants.
  * @return mixed A successful call returns the value of the requested PDO attribute.
  * An unsuccessful call returns null.
  */
 public function getAttribute($attribute)
 {
     try {
         return parent::getAttribute($attribute);
     } catch (\PDOException $e) {
         switch ($attribute) {
             case PDO::ATTR_SERVER_VERSION:
                 return $this->query("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR)")->fetchColumn();
             default:
                 throw $e;
         }
     }
 }
Example #2
0
 /**
  * Creates the PDO instance.
  *
  * This method is called by {@see \rock\db\Connection::open()} to establish a DB connection.
  * The default implementation will create a PHP PDO instance.
  * You may override this method if the default PDO needs to be adapted for certain DBMS.
  * @return PDO the pdo instance
  */
 protected function createPdoInstance()
 {
     $pdoClass = $this->pdoClass;
     if ($pdoClass === null) {
         $pdoClass = 'PDO';
         if ($this->_driverName !== null) {
             $driver = $this->_driverName;
         } elseif (($pos = strpos($this->dsn, ':')) !== false) {
             $driver = strtolower(substr($this->dsn, 0, $pos));
         }
         if (isset($driver) && ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv')) {
             $pdoClass = \rock\db\mssql\PDO::className();
         }
     }
     return new $pdoClass($this->dsn, $this->username, $this->password, $this->attributes);
 }