public static function initConnection($conparams, $name, $defaultClass = Propel::CLASS_PROPEL_PDO)
    {
        $adapter = isset($conparams['adapter']) ? DBAdapter::factory($conparams['adapter']) : self::getDB($name);

        if (null === $conparams['dsn']) {
            throw new PropelException('No dsn specified in your connection parameters for datasource [' . $name . ']');
        }

        $conparams = $adapter->prepareParams($conparams);

        if (isset($conparams['classname']) && !empty($conparams['classname'])) {
            $classname = $conparams['classname'];
            if (!class_exists($classname)) {
                throw new PropelException('Unable to load specified PDO subclass: ' . $classname);
            }
        } else {
            $classname = $defaultClass;
        }

        $dsn = $conparams['dsn'];
        $user = isset($conparams['user']) ? $conparams['user'] : null;
        $password = isset($conparams['password']) ? $conparams['password'] : null;

        // load any driver options from the config file
        // driver options are those PDO settings that have to be passed during the connection construction
        $driver_options = array();
        if (isset($conparams['options']) && is_array($conparams['options'])) {
            try {
                self::processDriverOptions($conparams['options'], $driver_options);
            } catch (PropelException $e) {
                throw new PropelException('Error processing driver options for datasource [' . $name . ']', $e);
            }
        }

        try {
            $con = new $classname($dsn, $user, $password, $driver_options);
            $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $con->setAttribute(PropelPDO::PROPEL_ATTR_CONNECTION_NAME, $name);
        } catch (PDOException $e) {
            throw new PropelException("Unable to open PDO connection", $e);
        }

        // load any connection options from the config file
        // connection attributes are those PDO flags that have to be set on the initialized connection
        if (isset($conparams['attributes']) && is_array($conparams['attributes'])) {
            $attributes = array();
            try {
                self::processDriverOptions($conparams['attributes'], $attributes);
            } catch (PropelException $e) {
                throw new PropelException('Error processing connection attributes for datasource [' . $name . ']', $e);
            }
            foreach ($attributes as $key => $value) {
                $con->setAttribute($key, $value);
            }
        }

        // initialize the connection using the settings provided in the config file. this could be a "SET NAMES <charset>" query for MySQL, for instance
        $adapter->initConnection($con, isset($conparams['settings']) && is_array($conparams['settings']) ? $conparams['settings'] : array());

        return $con;
    }
public static function initConnection($conparams, $name, $defaultClass = Propel::CLASS_PROPEL_PDO)
    {
        $adapter = isset($conparams['adapter']) ? DBAdapter::factory($conparams['adapter']) : self::getDB($name);

        if (null === $conparams['dsn']) {
            throw new PropelException('No dsn specified in your connection parameters for datasource [' . $name . ']');
        }

        $conparams = $adapter->prepareParams($conparams);

        if (isset($conparams['classname']) && !empty($conparams['classname'])) {
            $classname = $conparams['classname'];
            if (!class_exists($classname)) {
                throw new PropelException('Unable to load specified PDO subclass: ' . $classname);
            }
        } else {
            $classname = $defaultClass;
        }

        $dsn = $conparams['dsn'];
        $user = isset($conparams['user']) ? $conparams['user'] : null;
        $password = isset($conparams['password']) ? $conparams['password'] : null;

        // load any driver options from the config file
        // driver options are those PDO settings that have to be passed during the connection construction
        $driver_options = array();
        if (isset($conparams['options']) && is_array($conparams['options'])) {
            try {
                self::processDriverOptions($conparams['options'], $driver_options);
            } catch (PropelException $e) {
                throw new PropelException('Error processing driver options for datasource [' . $name . ']', $e);
            }
        }

        try {
            $con = new $classname($dsn, $user, $password, $driver_options);
            $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $con->setAttribute(PropelPDO::PROPEL_ATTR_CONNECTION_NAME, $name);
        } catch (PDOException $e) {
            throw new PropelException("Unable to open PDO connection", $e);
        }

        // load any connection options from the config file
        // connection attributes are those PDO flags that have to be set on the initialized connection
        if (isset($conparams['attributes']) && is_array($conparams['attributes'])) {
            $attributes = array();
            try {
                self::processDriverOptions($conparams['attributes'], $attributes);
            } catch (PropelException $e) {
                throw new PropelException('Error processing connection attributes for datasource [' . $name . ']', $e);
            }
            foreach ($attributes as $key => $value) {
                $con->setAttribute($key, $value);
            }
        }

        // initialize the connection using the settings provided in the config file. this could be a "SET NAMES <charset>" query for MySQL, for instance
        $adapter->initConnection($con, isset($conparams['settings']) && is_array($conparams['settings']) ? $conparams['settings'] : array());

        return $con;
    }
public static function initConnection ( $ conparams , $ name , $ defaultClass = Propel :: CLASS_PROPEL_PDO ) { $ adapter = isset ( $ conparams [ 'adapter' ] ) ? DBAdapter :: factory ( $ conparams [ 'adapter' ] ) : self :: getDB ( $ name ) ; if ( null === $ conparams [ 'dsn' ] ) { throw new PropelException ( 'No dsn specified in your connection parameters for datasource [' . $ name . ']' ) ; } $ conparams = $ adapter -> prepareParams ( $ conparams ) ; if ( isset ( $ conparams [ 'classname' ] ) && ! empty ( $ conparams [ 'classname' ] ) ) { $ classname = $ conparams [ 'classname' ] ; if ( ! class_exists ( $ classname ) ) { throw new PropelException ( 'Unable to load specified PDO subclass: ' . $ classname ) ; } } else { $ classname = $ defaultClass ; } $ dsn = $ conparams [ 'dsn' ] ; $ user = isset ( $ conparams [ 'user' ] ) ? $ conparams [ 'user' ] : null ; $ password = isset ( $ conparams [ 'password' ] ) ? $ conparams [ 'password' ] : null ; // load any driver options from the config file // driver options are those PDO settings that have to be passed during the connection construction $ driver_options = array ( ) ; if ( isset ( $ conparams [ 'options' ] ) && is_array ( $ conparams [ 'options' ] ) ) { try { self :: processDriverOptions ( $ conparams [ 'options' ] , $ driver_options ) ; } catch ( PropelException $ e ) { throw new PropelException ( 'Error processing driver options for datasource [' . $ name . ']' , $ e ) ; } } try { $ con = new $ classname ( $ dsn , $ user , $ password , $ driver_options ) ; $ con -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; $ con -> setAttribute ( PropelPDO :: PROPEL_ATTR_CONNECTION_NAME , $ name ) ; } catch ( PDOException $ e ) { throw new PropelException ( "Unable to open PDO connection" , $ e ) ; } // load any connection options from the config file // connection attributes are those PDO flags that have to be set on the initialized connection if ( isset ( $ conparams [ 'attributes' ] ) && is_array ( $ conparams [ 'attributes' ] ) ) { $ attributes = array ( ) ; try { self :: processDriverOptions ( $ conparams [ 'attributes' ] , $ attributes ) ; } catch ( PropelException $ e ) { throw new PropelException ( 'Error processing connection attributes for datasource [' . $ name . ']' , $ e ) ; } foreach ( $ attributes as $ key => $ value ) { $ con -> setAttribute ( $ key , $ value ) ; } } // initialize the connection using the settings provided in the config file. this could be a "SET NAMES <charset>" query for MySQL, for instance $ adapter -> initConnection ( $ con , isset ( $ conparams [ 'settings' ] ) && is_array ( $ conparams [ 'settings' ] ) ? $ conparams [ 'settings' ] : array ( ) ) ; return $ con ; }
Opens a new PDO connection for passed-in db name.

@param array  $conparams    Connection paramters.
@param string $name         Datasource name.
@param string $defaultClass The PDO subclass to instantiate if there is no explicit classname
specified in the connection params (default is Propel::CLASS_PROPEL_PDO)

@return PDO A database connection of the given class (PDO, PropelPDO, SlavePDO or user-defined)

@throws PropelException - if lower-level exception caught when trying to connect.
Opens a new PDO connection for passed - in db name .