From d1cf0527cefa67bca8142b8d52a514b1abd680e7 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 8 Jan 2013 02:12:58 +0400 Subject: [PATCH] Fixes #645: CDbConnection now throws CDbException when failed to open DB connection instead of failing with a warning --- CHANGELOG | 1 + framework/db/CDbConnection.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 2c60109b1..107468417 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Version 1.1.14 work in progress - Bug #150: Fixed CWidget was not switching between view paths when using themes (antoncpu) - Bug #1915: CDataProviderIterator: fixed init in case of disabled pagination (antoncpu) - Enh #1847: Added COutputCache::varyByLanguage to generate separate cache for different languages (Obramko) +- Chg #645: CDbConnection now throws CDbException when failed to open DB connection instead of failing with a warning (kidol, eirikhm, samdark) - Chg #1891: Changed order of methods in models generated by Gii and yiic, added better description of search method (hijarian, samdark) - New #1785: Added CPasswordHelper (tom--) diff --git a/framework/db/CDbConnection.php b/framework/db/CDbConnection.php index cfd547797..00641c1c7 100644 --- a/framework/db/CDbConnection.php +++ b/framework/db/CDbConnection.php @@ -406,6 +406,7 @@ class CDbConnection extends CApplicationComponent * Creates the PDO instance. * When some functionalities are missing in the pdo driver, we may use * an adapter class to provides them. + * @throws CDbException when failed to open DB connection * @return PDO the pdo instance */ protected function createPdoInstance() @@ -419,8 +420,12 @@ class CDbConnection extends CApplicationComponent elseif($driver==='sqlsrv') $pdoClass='CMssqlSqlsrvPdoAdapter'; } - return new $pdoClass($this->connectionString,$this->username, + @$instance=new $pdoClass($this->connectionString,$this->username, $this->password,$this->_attributes); + if(!$instance) + throw new CDbException(Yii::t('yii', 'CDbConnection failed to open the DB connection')); + + return $instance; } /**