public function open()
{
if ($this->pdo !== null) {
return;
}
if (!empty($this->masters)) {
$db = $this->openFromPool($this->masters, $this->masterConfig);
if ($db !== null) {
$this->pdo = $db->pdo;
return;
} else {
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;
try {
Yii::info($token, __METHOD__);
Yii::beginProfile($token, __METHOD__);
$this->pdo = $this->createPdoInstance();
$this->initConnection();
Yii::endProfile($token, __METHOD__);
} catch (\PDOException $e) {
Yii::endProfile($token, __METHOD__);
throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e);
}
}