|
|
|
@ -89,7 +89,8 @@ use yii\caching\Cache;
|
|
|
|
|
* ] |
|
|
|
|
* ~~~ |
|
|
|
|
* |
|
|
|
|
* @property string $driverName Name of the DB driver. This property is read-only. |
|
|
|
|
* @property string $driverName Name of the DB driver. Change this property if you want to override the |
|
|
|
|
* driver name specified in [[dsn]]. This can be useful if you're working with the database via ODBC layer. |
|
|
|
|
* @property boolean $isActive Whether the DB connection is established. This property is read-only. |
|
|
|
|
* @property string $lastInsertID The row ID of the last row inserted, or the last value retrieved from the |
|
|
|
|
* sequence object. This property is read-only. |
|
|
|
@ -261,6 +262,10 @@ class Connection extends Component
|
|
|
|
|
* @var Schema the database schema |
|
|
|
|
*/ |
|
|
|
|
private $_schema; |
|
|
|
|
/** |
|
|
|
|
* @var string driver name |
|
|
|
|
*/ |
|
|
|
|
private $_driverName; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a value indicating whether the DB connection is established. |
|
|
|
@ -348,11 +353,13 @@ class Connection extends Component
|
|
|
|
|
$pdoClass = $this->pdoClass; |
|
|
|
|
if ($pdoClass === null) { |
|
|
|
|
$pdoClass = 'PDO'; |
|
|
|
|
if (($pos = strpos($this->dsn, ':')) !== false) { |
|
|
|
|
if ($this->_driverName !== null) { |
|
|
|
|
$driver = $this->_driverName; |
|
|
|
|
} elseif (($pos = strpos($this->dsn, ':')) !== false) { |
|
|
|
|
$driver = strtolower(substr($this->dsn, 0, $pos)); |
|
|
|
|
if ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv') { |
|
|
|
|
$pdoClass = 'yii\db\mssql\PDO'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (isset($driver) && ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv')) { |
|
|
|
|
$pdoClass = 'yii\db\mssql\PDO'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -533,17 +540,29 @@ class Connection extends Component
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the name of the DB driver for the current [[dsn]]. |
|
|
|
|
* Returns the name of the DB driver. Based on the the current [[dsn]], in case it was not set explicitly |
|
|
|
|
* by an end user. |
|
|
|
|
* @return string name of the DB driver |
|
|
|
|
*/ |
|
|
|
|
public function getDriverName() |
|
|
|
|
{ |
|
|
|
|
if (($pos = strpos($this->dsn, ':')) !== false) { |
|
|
|
|
return strtolower(substr($this->dsn, 0, $pos)); |
|
|
|
|
} else { |
|
|
|
|
$this->open(); |
|
|
|
|
|
|
|
|
|
return strtolower($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME)); |
|
|
|
|
if ($this->_driverName === null) { |
|
|
|
|
if (($pos = strpos($this->dsn, ':')) !== false) { |
|
|
|
|
$this->_driverName = strtolower(substr($this->dsn, 0, $pos)); |
|
|
|
|
} else { |
|
|
|
|
$this->open(); |
|
|
|
|
$this->_driverName = strtolower($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $this->_driverName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Changes the current driver name. |
|
|
|
|
* @param string $driverName name of the DB driver |
|
|
|
|
*/ |
|
|
|
|
public function setDriverName($driverName) |
|
|
|
|
{ |
|
|
|
|
$this->_driverName = strtolower($driverName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|