Driver.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Doctrine\DBAL\Driver\SQLSrv;
  3. use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
  4. /**
  5. * Driver for ext/sqlsrv.
  6. */
  7. class Driver extends AbstractSQLServerDriver
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  13. {
  14. if (! isset($params['host'])) {
  15. throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
  16. }
  17. $serverName = $params['host'];
  18. if (isset($params['port'])) {
  19. $serverName .= ', ' . $params['port'];
  20. }
  21. if (isset($params['dbname'])) {
  22. $driverOptions['Database'] = $params['dbname'];
  23. }
  24. if (isset($params['charset'])) {
  25. $driverOptions['CharacterSet'] = $params['charset'];
  26. }
  27. if ($username !== null) {
  28. $driverOptions['UID'] = $username;
  29. }
  30. if ($password !== null) {
  31. $driverOptions['PWD'] = $password;
  32. }
  33. if (! isset($driverOptions['ReturnDatesAsStrings'])) {
  34. $driverOptions['ReturnDatesAsStrings'] = 1;
  35. }
  36. return new SQLSrvConnection($serverName, $driverOptions);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getName()
  42. {
  43. return 'sqlsrv';
  44. }
  45. }