Skip to content
PHP Ecosystem
Explore

PDO

API reference › yii › db › mssql › PDO

classyii\db\mssql\PDO
ExtendsPDO
Since2.0
Sourceframework/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.

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.

MethodDescriptionDefined 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
ConstantValueDescriptionDefined by
SQLSRV_ATTR_ENCODING1000A constant for the pdo_sqlsrv encoding attribute. Pass as a key in Connection::$attributes.PDO
SQLSRV_ENCODING_SYSTEM3A 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_UTF865001A constant for UTF-8 string encoding. This is the pdo_sqlsrv default for PDO::PARAM_STR parameters.PDO
public function beginTransaction(): bool

Starts 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.

public function commit(): bool

Commits 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.

public function getAttribute(int $attribute): mixed

Retrieve 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

ParameterTypeDescription
$attributeintOne of the PDO::ATTR_* constants.

Returns

mixed: A successful call returns the value of the requested PDO attribute. An unsuccessful call returns null.

public function lastInsertId(string|null $sequence = null): string|false

Returns value of the last inserted ID.

Parameters

ParameterTypeDescription
$sequencestring|nullThe sequence name. Defaults to null.

Returns

string|false: Last inserted ID value.

public function rollBack(): bool

Rollbacks 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.