PDO
API reference › yii › db › mssql › PDO
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.
The SQLSRV_ATTR_ENCODING and SQLSRV_ENCODING_SYSTEM constants can be used in Connection::$attributes
to eliminate the implicit nvarchar conversion overhead on char/varchar indexed columns.
Methods
Section titled “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. | PDO |
commit() | Commits a transaction. It is necessary to override PDO’s method as MSSQL PDO driver does not natively support transactions. | PDO |
getAttribute() | Retrieve a database connection attribute. | PDO |
lastInsertId() | Returns value of the last inserted ID. | PDO |
rollBack() | Rollbacks a transaction. It is necessary to override PDO’s method as MSSQL PDO driver does not natively support transactions. | PDO |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
SQLSRV_ATTR_ENCODING | 1000 | A constant for the pdo_sqlsrv encoding attribute. Pass as a key in Connection::$attributes. | PDO |
SQLSRV_ENCODING_SYSTEM | 3 | A constant for ANSI (system code page) string encoding. Use with SQLSRV_ATTR_ENCODING to avoid the implicit nvarchar-to-varchar conversion that degrades performance on char/varchar indexed columns. | PDO |
SQLSRV_ENCODING_UTF8 | 65001 | A constant for UTF-8 string encoding. This is the pdo_sqlsrv default for PDO::PARAM_STR parameters. | PDO |
Method details
Section titled “Method details”beginTransaction()
Section titled “beginTransaction() ”public function beginTransaction(): boolStarts a transaction. It is necessary to override PDO’s method as MSSQL PDO driver does not natively support transactions.
Returns
bool: The result of a transaction start.
commit()
Section titled “commit() ”public function commit(): boolCommits a transaction. It is necessary to override PDO’s method as MSSQL PDO driver does not natively support transactions.
Returns
bool: The result of a transaction commit.
getAttribute()
Section titled “getAttribute() ”public function getAttribute(int $attribute): mixedRetrieve a database connection attribute.
It is necessary to override PDO’s method as some MSSQL PDO driver (for example, dblib) does not support getting attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | One of the PDO::ATTR_* constants. |
Returns
mixed: A successful call returns the value of the requested PDO attribute. An unsuccessful call returns null.
lastInsertId()
Section titled “lastInsertId() ”public function lastInsertId(string|null $sequence = null): string|falseReturns value of the last inserted ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sequence | string| | The sequence name. Defaults to null. |
Returns
string|false: Last inserted ID value.
rollBack()
Section titled “rollBack() ”public function rollBack(): boolRollbacks a transaction. It is necessary to override PDO’s method as MSSQL PDO driver does not natively support transactions.
Returns
bool: The result of a transaction roll back.