mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 13:58:55 +08:00
Fixes #1650: Added Connection::pdoClass.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user