sqlserver.php 977 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php namespace Laravel\Database\Connectors; use PDO;
  2. class SQLServer extends Connector {
  3. /**
  4. * The PDO connection options.
  5. *
  6. * @var array
  7. */
  8. protected $options = array(
  9. PDO::ATTR_CASE => PDO::CASE_LOWER,
  10. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  11. PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
  12. PDO::ATTR_STRINGIFY_FETCHES => false,
  13. );
  14. /**
  15. * Establish a PDO database connection.
  16. *
  17. * @param array $config
  18. * @return PDO
  19. */
  20. public function connect($config)
  21. {
  22. extract($config);
  23. // Format the SQL Server connection string. This connection string format can
  24. // also be used to connect to Azure SQL Server databases. The port is defined
  25. // directly after the server name, so we'll create that and then create the
  26. // final DSN string to pass to PDO.
  27. $port = (isset($port)) ? ','.$port : '';
  28. $dsn = "sqlsrv:Server={$host}{$port};Database={$database}";
  29. return new PDO($dsn, $username, $password, $this->options($config));
  30. }
  31. }