cleaning up code.
This commit is contained in:
@@ -12,24 +12,26 @@ class MySQL extends Connector {
|
||||
{
|
||||
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}";
|
||||
|
||||
// Check for any optional MySQL PDO options. These options are not required
|
||||
// to establish a PDO connection; however, may be needed in certain server
|
||||
// or hosting environments used by the developer.
|
||||
foreach (array('port', 'unix_socket') as $key)
|
||||
// The developer has the freedom of specifying a port for the MySQL database
|
||||
// or the default port (3306) will be used to make the connection by PDO.
|
||||
// The Unix socket may also be specified if necessary.
|
||||
if (isset($config['port']))
|
||||
{
|
||||
if (isset($config[$key]))
|
||||
{
|
||||
$dsn .= ";{$key}={$config[$key]}";
|
||||
}
|
||||
$dsn .= ";port={$config['port']}";
|
||||
}
|
||||
|
||||
if (isset($config['unix_socket']))
|
||||
{
|
||||
$dsn .= ";unix_socket={$config['unix_socket']}";
|
||||
}
|
||||
|
||||
$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']))
|
||||
{
|
||||
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
|
||||
|
||||
Reference in New Issue
Block a user