public function open()
    {
        if ($this->pdo !== null) {
            return;
        }

        if (!empty($this->masters)) {
            $db = $this->getMaster();
            if ($db !== null) {
                $this->pdo = $db->pdo;
                return;
            }

            throw new InvalidConfigException('None of the master DB servers is available.');
        }

        if (empty($this->dsn)) {
            throw new InvalidConfigException('Connection::dsn cannot be empty.');
        }

        $token = 'Opening DB connection: ' . $this->dsn;
        $enableProfiling = $this->enableProfiling;
        try {
            Yii::info($token, __METHOD__);
            if ($enableProfiling) {
                Yii::beginProfile($token, __METHOD__);
            }

            $this->pdo = $this->createPdoInstance();
            $this->initConnection();

            if ($enableProfiling) {
                Yii::endProfile($token, __METHOD__);
            }
        } catch (\PDOException $e) {
            if ($enableProfiling) {
                Yii::endProfile($token, __METHOD__);
            }

            throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e);
        }
    }
public function open()
    {
        if ($this->pdo !== null) {
            return;
        }

        if (!empty($this->masters)) {
            $db = $this->getMaster();
            if ($db !== null) {
                $this->pdo = $db->pdo;
                return;
            }

            throw new InvalidConfigException('None of the master DB servers is available.');
        }

        if (empty($this->dsn)) {
            throw new InvalidConfigException('Connection::dsn cannot be empty.');
        }

        $token = 'Opening DB connection: ' . $this->dsn;
        $enableProfiling = $this->enableProfiling;
        try {
            Yii::info($token, __METHOD__);
            if ($enableProfiling) {
                Yii::beginProfile($token, __METHOD__);
            }

            $this->pdo = $this->createPdoInstance();
            $this->initConnection();

            if ($enableProfiling) {
                Yii::endProfile($token, __METHOD__);
            }
        } catch (\PDOException $e) {
            if ($enableProfiling) {
                Yii::endProfile($token, __METHOD__);
            }

            throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e);
        }
    }
public function open ( ) { if ( $ this -> pdo !== null ) { return ; } if ( ! empty ( $ this -> masters ) ) { $ db = $ this -> getMaster ( ) ; if ( $ db !== null ) { $ this -> pdo = $ db -> pdo ; return ; } throw new InvalidConfigException ( 'None of the master DB servers is available.' ) ; } if ( empty ( $ this -> dsn ) ) { throw new InvalidConfigException ( 'Connection::dsn cannot be empty.' ) ; } $ token = 'Opening DB connection: ' . $ this -> dsn ; $ enableProfiling = $ this -> enableProfiling ; try { Yii :: info ( $ token , __METHOD__ ) ; if ( $ enableProfiling ) { Yii :: beginProfile ( $ token , __METHOD__ ) ; } $ this -> pdo = $ this -> createPdoInstance ( ) ; $ this -> initConnection ( ) ; if ( $ enableProfiling ) { Yii :: endProfile ( $ token , __METHOD__ ) ; } } catch ( \ PDOException $ e ) { if ( $ enableProfiling ) { Yii :: endProfile ( $ token , __METHOD__ ) ; } throw new Exception ( $ e -> getMessage ( ) , $ e -> errorInfo , ( int ) $ e -> getCode ( ) , $ e ) ; } }
Establishes a DB connection.
It does nothing if a DB connection has already been established.
@throws Exception if connection fails
Establishes a DB connection . It does nothing if a DB connection has already been established .