SqlsrvPDO.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\mssql;
  8. /**
  9. * This is an extension of the default PDO class of SQLSRV driver.
  10. * It provides workarounds for improperly implemented functionalities of the SQLSRV driver.
  11. *
  12. * @author Timur Ruziev <resurtm@gmail.com>
  13. * @since 2.0
  14. */
  15. class SqlsrvPDO extends \PDO
  16. {
  17. /**
  18. * Returns value of the last inserted ID.
  19. *
  20. * SQLSRV driver implements [[PDO::lastInsertId()]] method but with a single peculiarity:
  21. * when `$sequence` value is a null or an empty string it returns an empty string.
  22. * But when parameter is not specified it works as expected and returns actual
  23. * last inserted ID (like the other PDO drivers).
  24. * @param string|null $sequence the sequence name. Defaults to null.
  25. * @return int last inserted ID value.
  26. */
  27. public function lastInsertId($sequence = null)
  28. {
  29. return !$sequence ? parent::lastInsertId() : parent::lastInsertId($sequence);
  30. }
  31. }