Connection.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Doctrine\DBAL\Driver\PDOSqlsrv;
  3. use Doctrine\DBAL\Driver\PDO;
  4. use Doctrine\DBAL\Driver\Result;
  5. /**
  6. * Sqlsrv Connection implementation.
  7. *
  8. * @deprecated Use {@link PDO\SQLSrv\Connection} instead.
  9. */
  10. class Connection extends PDO\Connection
  11. {
  12. /**
  13. * {@inheritdoc}
  14. *
  15. * @internal The connection can be only instantiated by its driver.
  16. *
  17. * @param string $dsn
  18. * @param string|null $user
  19. * @param string|null $password
  20. * @param mixed[]|null $options
  21. */
  22. public function __construct($dsn, $user = null, $password = null, ?array $options = null)
  23. {
  24. parent::__construct($dsn, $user, $password, $options);
  25. $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [PDO\SQLSrv\Statement::class, []]);
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function lastInsertId($name = null)
  31. {
  32. if ($name === null) {
  33. return parent::lastInsertId($name);
  34. }
  35. $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
  36. $stmt->execute([$name]);
  37. if ($stmt instanceof Result) {
  38. return $stmt->fetchOne();
  39. }
  40. return $stmt->fetchColumn();
  41. }
  42. }