# SqlsrvPDO

> This is an extension of the default PDO class of SQLSRV driver.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [mssql](/docs/api/yii/db/mssql/index.md) › SqlsrvPDO

| class | `yii\db\mssql\SqlsrvPDO` |
| --- | --- |
| Extends | [`PDO`](https://www.php.net/manual/en/class.pdo.php) |
| Since | 2.0 |
| Source | [`framework/db/mssql/SqlsrvPDO.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/mssql/SqlsrvPDO.php#L21) |

This is an extension of the default PDO class of SQLSRV driver.

It provides workarounds for improperly implemented functionalities of the SQLSRV driver.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`lastInsertId()`](#method-lastInsertId) | Returns value of the last inserted ID. | `SqlsrvPDO` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-SQLSRV_ATTR_ENCODING"></span>`SQLSRV_ATTR_ENCODING` | `1000` | A constant for the pdo_sqlsrv encoding attribute. Pass as a key in [`Connection::$attributes`](/docs/api/yii/db/connection/index.md#property-attributes). | `SqlsrvPDO` |
| <span id="const-SQLSRV_ENCODING_SYSTEM"></span>`SQLSRV_ENCODING_SYSTEM` | `3` | A constant for ANSI (system code page) string encoding. Use with [`SQLSRV_ATTR_ENCODING`](/docs/api/yii/db/mssql/sqlsrvpdo/index.md#const-SQLSRV_ATTR_ENCODING) to avoid the implicit `nvarchar`-to-`varchar` conversion that degrades performance on `char`/`varchar` indexed columns. | `SqlsrvPDO` |
| <span id="const-SQLSRV_ENCODING_UTF8"></span>`SQLSRV_ENCODING_UTF8` | `65001` | A constant for UTF-8 string encoding. This is the pdo_sqlsrv default for [`PDO::PARAM_STR`](https://www.php.net/manual/en/class.pdo.php) parameters. | `SqlsrvPDO` |

## Method details

### lastInsertId() <span id="method-lastInsertId"></span>

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

Returns value of the last inserted ID.

SQLSRV driver implements [`PDO::lastInsertId()`](/docs/api/yii/db/mssql/pdo/index.md#method-lastInsertId) method but with a single peculiarity:
- when `$sequence` value is a null or an empty string it returns an empty string.
- but when parameter is not specified it works as expected and returns actual
- last inserted ID (like the other PDO drivers).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sequence` | `string\|null` | The sequence name. Defaults to `null`. |

**Returns**

`string|false`: Last inserted ID value.