merged skunkworks into develop.
This commit is contained in:
@@ -16,7 +16,7 @@ abstract class Connector {
|
||||
);
|
||||
|
||||
/**
|
||||
* Establish a PDO database connection for a given database configuration.
|
||||
* Establish a PDO database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
@@ -24,7 +24,7 @@ abstract class Connector {
|
||||
abstract public function connect($config);
|
||||
|
||||
/**
|
||||
* Get the PDO connection options for a given database configuration.
|
||||
* Get the PDO connection options for the configuration.
|
||||
*
|
||||
* Developer specified options will override the default connection options.
|
||||
*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class MySQL extends Connector {
|
||||
|
||||
/**
|
||||
* Establish a PDO database connection for a given database configuration.
|
||||
* Establish a PDO database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
@@ -15,7 +15,7 @@ class MySQL extends Connector {
|
||||
// Format the initial MySQL PDO connection string. These options are required
|
||||
// for every MySQL connection that is established. The connection strings
|
||||
// have the following convention: "mysql:host=hostname;dbname=database"
|
||||
$dsn = sprintf('%s:host=%s;dbname=%s', $driver, $host, $database);
|
||||
$dsn = "mysql:host={$host};dbname={$database}";
|
||||
|
||||
// Check for any optional MySQL PDO options. These options are not required
|
||||
// to establish a PDO connection; however, may be needed in certain server
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class Postgres extends Connector {
|
||||
|
||||
/**
|
||||
* Establish a PDO database connection for a given database configuration.
|
||||
* Establish a PDO database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
@@ -15,7 +15,7 @@ class Postgres extends Connector {
|
||||
// Format the initial Postgres PDO connection string. These options are required
|
||||
// for every Postgres connection that is established. The connection strings
|
||||
// have the following convention: "pgsql:host=hostname;dbname=database"
|
||||
$dsn = sprintf('%s:host=%s;dbname=%s', $driver, $host, $database);
|
||||
$dsn = "pgsql:host={$host};dbname={$database}";
|
||||
|
||||
// Check for any optional Postgres PDO options. These options are not required
|
||||
// to establish a PDO connection; however, may be needed in certain server
|
||||
|
||||
@@ -3,25 +3,7 @@
|
||||
class SQLite extends Connector {
|
||||
|
||||
/**
|
||||
* The path to the SQLite databases for the application.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Create a new SQLite database connector instance.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a PDO database connection for a given database configuration.
|
||||
* Establish a PDO database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
@@ -32,27 +14,19 @@ class SQLite extends Connector {
|
||||
|
||||
// SQLite provides supported for "in-memory" databases, which exist only for the
|
||||
// lifetime of the request. Any given in-memory database may only have one PDO
|
||||
// connection open to it at a time. Generally, these databases are use for
|
||||
// connection open to it at a time. Generally, these databases are used for
|
||||
// testing and development purposes, not in production scenarios.
|
||||
if ($config['database'] == ':memory:')
|
||||
{
|
||||
return new PDO('sqlite::memory:', null, null, $options);
|
||||
}
|
||||
|
||||
// First, we will check for the database in the default storage directory for the
|
||||
// application. If we don't find the database there, we will assume the database
|
||||
// name is actually a full qualified path to the database on disk and attempt
|
||||
// to load it. If we still can't find it, we'll bail out.
|
||||
elseif (file_exists($path = $this->path.$config['database'].'.sqlite'))
|
||||
if (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
|
||||
{
|
||||
return new PDO('sqlite:'.$path, null, null, $options);
|
||||
}
|
||||
elseif (file_exists($config['database']))
|
||||
{
|
||||
return new PDO('sqlite:'.$config['database'], null, null, $options);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException("SQLite database [{$config['database']}] could not be found.");
|
||||
throw new \Exception("SQLite database [{$config['database']}] could not be found.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
38
laravel/database/connectors/sqlserver.php
Normal file
38
laravel/database/connectors/sqlserver.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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
|
||||
// directly after the server name, so we'll create that and then create the
|
||||
// final DSN string to pass to PDO.
|
||||
$port = (isset($port)) ? ','.$port : '';
|
||||
|
||||
$dsn = "sqlsrv:Server={$host}{$port};Database={$database}";
|
||||
|
||||
return new PDO($dsn, $username, $password, $this->options($config));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user