From 4a552c88cff62c3d84f478e289e75dbf05bc1498 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 27 Dec 2013 16:01:39 -0500 Subject: [PATCH] Fixes #1650: Added Connection::pdoClass. --- framework/CHANGELOG.md | 1 + framework/yii/db/Connection.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b3c13e5..b7699ac 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -35,6 +35,7 @@ Yii Framework 2 Change Log - Enh #1634: Use masked CSRF tokens to prevent BREACH exploits (qiangxue) - Enh #1641: Added `BaseActiveRecord::updateAttributes()` (qiangxue) - Enh #1646: Added postgresql `QueryBuilder::checkIntegrity` and `QueryBuilder::resetSequence` (Ragazzo) +- Enh #1645: Added `Connection::$pdoClass` property (Ragazzo) - Enh: Added `favicon.ico` and `robots.txt` to defauly application templates (samdark) - Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue) - Enh: Support for file aliases in console command 'message' (omnilight) diff --git a/framework/yii/db/Connection.php b/framework/yii/db/Connection.php index ef5be87..030e6c7 100644 --- a/framework/yii/db/Connection.php +++ b/framework/yii/db/Connection.php @@ -253,7 +253,10 @@ class Connection extends Component * @var Schema the database schema */ private $_schema; - + /** + * @var string Custom PDO wrapper class. If not set, it will use "PDO" or "yii\db\mssql\PDO" when MSSQL is used. + */ + public $pdoClass; /** * Returns a value indicating whether the DB connection is established. @@ -338,13 +341,17 @@ class Connection extends Component */ protected function createPdoInstance() { - $pdoClass = 'PDO'; - if (($pos = strpos($this->dsn, ':')) !== false) { - $driver = strtolower(substr($this->dsn, 0, $pos)); - if ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv') { - $pdoClass = 'yii\db\mssql\PDO'; + $pdoClass = $this->pdoClass; + if ($pdoClass === null) { + $pdoClass = 'PDO'; + if (($pos = strpos($this->dsn, ':')) !== false) { + $driver = strtolower(substr($this->dsn, 0, $pos)); + if ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv') { + $pdoClass = 'yii\db\mssql\PDO'; + } } } + return new $pdoClass($this->dsn, $this->username, $this->password, $this->attributes); }