Zend_Db_Adapter_Pdo_Abstract::_connect PHP Method

_connect() protected method

Creates a PDO object and connects to the database.
protected _connect ( ) : void
return void
    protected function _connect()
    {
        // if we already have a PDO object, no need to re-connect.
        if ($this->_connection) {
            return;
        }
        // get the dsn first, because some adapters alter the $_pdoType
        $dsn = $this->_dsn();
        // check for PDO extension
        if (!extension_loaded('pdo')) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
        }
        // check the PDO driver is available
        if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
        }
        // create PDO connection
        $q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);
        // add the persistence flag if we find it in our config array
        if (isset($this->_config['persistent']) && $this->_config['persistent'] == true) {
            $this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true;
        }
        try {
            $this->_connection = new PDO($dsn, $this->_config['username'], $this->_config['password'], $this->_config['driver_options']);
            $this->_profiler->queryEnd($q);
            // set the PDO connection to perform case-folding on array keys, or not
            $this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
            // always use exceptions.
            $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

Example #1
0
 /**
  * @return void
  */
 protected function _connect()
 {
     if ($this->_connection) {
         return;
     }
     parent::_connect();
     $this->_connection->exec('SET QUOTED_IDENTIFIER ON');
 }
All Usage Examples Of Zend_Db_Adapter_Pdo_Abstract::_connect