Class yii\db\mssql\PDO
| Inheritance | yii\db\mssql\PDO » PDO |
|---|---|
| Available since version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/db/mssql/PDO.php |
This is an extension of the default PDO class of MSSQL and DBLIB drivers.
It provides workarounds for improperly implemented functionalities of the MSSQL and DBLIB drivers.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| beginTransaction() | Starts a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions. | yii\db\mssql\PDO |
| commit() | Commits a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions. | yii\db\mssql\PDO |
| getAttribute() | Retrieve a database connection attribute. | yii\db\mssql\PDO |
| lastInsertId() | Returns value of the last inserted ID. | yii\db\mssql\PDO |
| rollBack() | Rollbacks a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions. | yii\db\mssql\PDO |
Method Details
Starts a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions.
| public boolean beginTransaction ( ) | ||
| return | boolean | The result of a transaction start. |
|---|---|---|
#[\ReturnTypeWillChange] public function beginTransaction() { $this->exec('BEGIN TRANSACTION'); return true; } Commits a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions.
| public boolean commit ( ) | ||
| return | boolean | The result of a transaction commit. |
|---|---|---|
#[\ReturnTypeWillChange] public function commit() { $this->exec('COMMIT TRANSACTION'); return true; } Retrieve a database connection attribute.
It is necessary to override PDO's method as some MSSQL PDO driver (e.g. dblib) does not support getting attributes.
| public mixed getAttribute ( integer $attribute ) | ||
| $attribute | integer | One of the PDO::ATTR_* constants. |
| return | mixed | A successful call returns the value of the requested PDO attribute. An unsuccessful call returns null. |
|---|---|---|
#[\ReturnTypeWillChange] public function getAttribute($attribute) { try { return parent::getAttribute($attribute); } catch (\PDOException $e) { switch ($attribute) { case self::ATTR_SERVER_VERSION: return $this->query("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR)")->fetchColumn(); default: throw $e; } } } Returns value of the last inserted ID.
| public string|false lastInsertId ( string|null $sequence = null ) | ||
| $sequence | string|null | The sequence name. Defaults to null. |
| return | string|false | Last inserted ID value. |
|---|---|---|
#[\ReturnTypeWillChange] public function lastInsertId($sequence = null) { return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn(); } Rollbacks a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not natively support transactions.
| public boolean rollBack ( ) | ||
| return | boolean | The result of a transaction roll back. |
|---|---|---|
#[\ReturnTypeWillChange] public function rollBack() { $this->exec('ROLLBACK TRANSACTION'); return true; }
Signup or Login in order to comment.