sqlserver.php 926 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php namespace Laravel\Database\Connectors; use PDO;

class SQLServer extends Connector {

	/**
	 * The PDO connection options.
	 *
	 * @var array
	 */
	protected $options = array(
			PDO::ATTR_CASE => PDO::CASE_LOWER,
			PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
			PDO::ATTR_STRINGIFY_FETCHES => false,
	);

	/**
	 * Establish a PDO database connection.
	 *
	 * @param  array  $config
	 * @return PDO
	 */
	public function connect($config)
	{
		extract($config);

		// Format the SQL Server connection string. This connection string format can
		// also be used to connect to Azure SQL Server databases. The port is defined
Taylor Otwell committed
29
		// directly after the server name, so we'll create that first.
30 31 32 33 34 35 36 37
		$port = (isset($port)) ? ','.$port : '';

		$dsn = "sqlsrv:Server={$host}{$port};Database={$database}";

		return new PDO($dsn, $username, $password, $this->options($config));
	}

}