sqlserver.php 926 B

12345678910111213141516171819202122232425262728293031323334353637
  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 first.
  26. $port = (isset($port)) ? ','.$port : '';
  27. $dsn = "sqlsrv:Server={$host}{$port};Database={$database}";
  28. return new PDO($dsn, $username, $password, $this->options($config));
  29. }
  30. }