Commit fe0b4b28 authored by Taylor Otwell's avatar Taylor Otwell

cleaning up code.

parent 33e49146
...@@ -12,24 +12,26 @@ class MySQL extends Connector { ...@@ -12,24 +12,26 @@ class MySQL extends Connector {
{ {
extract($config); extract($config);
// 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 = "mysql:host={$host};dbname={$database}"; $dsn = "mysql:host={$host};dbname={$database}";
// Check for any optional MySQL PDO options. These options are not required // The developer has the freedom of specifying a port for the MySQL database
// to establish a PDO connection; however, may be needed in certain server // or the default port (3306) will be used to make the connection by PDO.
// or hosting environments used by the developer. // The Unix socket may also be specified if necessary.
foreach (array('port', 'unix_socket') as $key) if (isset($config['port']))
{ {
if (isset($config[$key])) $dsn .= ";port={$config['port']}";
{
$dsn .= ";{$key}={$config[$key]}";
} }
if (isset($config['unix_socket']))
{
$dsn .= ";unix_socket={$config['unix_socket']}";
} }
$connection = new PDO($dsn, $username, $password, $this->options($config)); $connection = new PDO($dsn, $username, $password, $this->options($config));
// If a character set has been specified, we'll execute a query against
// the database to set the correct character set. By default, this is
// set to UTF-8 which should be fine for most scenarios.
if (isset($config['charset'])) if (isset($config['charset']))
{ {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute(); $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
......
...@@ -12,24 +12,21 @@ class Postgres extends Connector { ...@@ -12,24 +12,21 @@ class Postgres extends Connector {
{ {
extract($config); extract($config);
// 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 = "pgsql:host={$host};dbname={$database}"; $dsn = "pgsql:host={$host};dbname={$database}";
// Check for any optional Postgres PDO options. These options are not required // The developer has the freedom of specifying a port for the PostgresSQL
// to establish a PDO connection; however, may be needed in certain server // database or the default port (5432) will be used by PDO to create the
// or hosting environments used by the developer. // connection to the database for the developer.
foreach (array('port') as $key => $value) if (isset($config['port']))
{ {
if (isset($config[$key])) $dsn .= ";port={$config['port']}";
{
$dsn .= ";{$key}={$value}";
}
} }
$connection = new PDO($dsn, $username, $password, $this->options($config)); $connection = new PDO($dsn, $username, $password, $this->options($config));
// If a character set has been specified, we'll execute a query against
// the database to set the correct character set. By default, this is
// set to UTF-8 which should be fine for most scenarios.
if (isset($config['charset'])) if (isset($config['charset']))
{ {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute(); $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
......
...@@ -26,8 +26,7 @@ class SQLServer extends Connector { ...@@ -26,8 +26,7 @@ class SQLServer extends Connector {
// Format the SQL Server connection string. This connection string format can // 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 // 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 // directly after the server name, so we'll create that first.
// final DSN string to pass to PDO.
$port = (isset($port)) ? ','.$port : ''; $port = (isset($port)) ? ','.$port : '';
$dsn = "sqlsrv:Server={$host}{$port};Database={$database}"; $dsn = "sqlsrv:Server={$host}{$port};Database={$database}";
......
...@@ -59,7 +59,10 @@ abstract class Grammar { ...@@ -59,7 +59,10 @@ abstract class Grammar {
// Expressions should be injected into the query as raw strings so // Expressions should be injected into the query as raw strings so
// so we do not want to wrap them in any way. We will just return // so we do not want to wrap them in any way. We will just return
// the string value from the expression to be included. // the string value from the expression to be included.
if ($value instanceof Expression) return $value->get(); if ($value instanceof Expression)
{
return $value->get();
}
// If the value being wrapped contains a column alias, we need to // If the value being wrapped contains a column alias, we need to
// wrap it a little differently as each segment must be wrapped // wrap it a little differently as each segment must be wrapped
......
...@@ -150,7 +150,7 @@ class Query { ...@@ -150,7 +150,7 @@ class Query {
{ {
// If the "column" is really an instance of a Closure, the developer is // If the "column" is really an instance of a Closure, the developer is
// trying to create a join with a complex "ON" clause. So, we will add // trying to create a join with a complex "ON" clause. So, we will add
// the join, and then call the Closure with the join. // the join, and then call the Closure with the join/
if ($column1 instanceof Closure) if ($column1 instanceof Closure)
{ {
$this->joins[] = new Query\Join($type, $table); $this->joins[] = new Query\Join($type, $table);
...@@ -435,7 +435,7 @@ class Query { ...@@ -435,7 +435,7 @@ class Query {
// //
// The index variable helps us get the correct parameter value // The index variable helps us get the correct parameter value
// for the where condition. We increment it each time we add // for the where condition. We increment it each time we add
// a condition to the query. // a condition to the query's where.
$connector = 'AND'; $connector = 'AND';
$index = 0; $index = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment