Driver.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Doctrine\DBAL\Driver\SQLSrv;
  3. use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
  4. use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost;
  5. use Doctrine\Deprecations\Deprecation;
  6. /**
  7. * Driver for ext/sqlsrv.
  8. */
  9. class Driver extends AbstractSQLServerDriver
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  15. {
  16. $serverName = '';
  17. if (isset($params['host'])) {
  18. $serverName = $params['host'];
  19. if (isset($params['port'])) {
  20. $serverName .= ',' . $params['port'];
  21. }
  22. } elseif (isset($params['port'])) {
  23. throw PortWithoutHost::new();
  24. }
  25. if (isset($params['dbname'])) {
  26. $driverOptions['Database'] = $params['dbname'];
  27. }
  28. if (isset($params['charset'])) {
  29. $driverOptions['CharacterSet'] = $params['charset'];
  30. }
  31. if ($username !== null) {
  32. $driverOptions['UID'] = $username;
  33. }
  34. if ($password !== null) {
  35. $driverOptions['PWD'] = $password;
  36. }
  37. if (! isset($driverOptions['ReturnDatesAsStrings'])) {
  38. $driverOptions['ReturnDatesAsStrings'] = 1;
  39. }
  40. return new Connection($serverName, $driverOptions);
  41. }
  42. /**
  43. * {@inheritdoc}
  44. *
  45. * @deprecated
  46. */
  47. public function getName()
  48. {
  49. Deprecation::trigger(
  50. 'doctrine/dbal',
  51. 'https://github.com/doctrine/dbal/issues/3580',
  52. 'Driver::getName() is deprecated'
  53. );
  54. return 'sqlsrv';
  55. }
  56. }