private static function singleton($alias, $driver, $user, $pass, $option)
{
try {
try {
$server_addr = $_SERVER['SERVER_ADDR'];
// Force column names to lower case
$option[\PDO::ATTR_CASE] = \PDO::CASE_LOWER;
// Establishes a persistent connection to the database
$option[\PDO::ATTR_PERSISTENT] = self::$persistent;
// Throws exceptions in development environment and report errors in production
$option[\PDO::ATTR_ERRMODE] = $server_addr == '127.0.0.1' || $server_addr == '::1' ? \PDO::ERRMODE_EXCEPTION : \PDO::ERRMODE_SILENT;
// Executes a command on the MySQL server to set the charset to UTF-8
$option[defined(\PDO::MYSQL_ATTR_INIT_COMMAND) ? \PDO::MYSQL_ATTR_INIT_COMMAND : 1002] = "SET NAMES utf8";
// Creates the instance with the settings
$instance = @new \PDO($driver, $user, $pass, $option);
self::setHandle($alias, $instance);
self::setInstance($alias);
} catch (\PDOException $e) {
$error = self::getErrorInfo($e);
if ($e->getMessage() == 'could not find driver' || $e->getMessage() == 'invalid data source name') {
throw new \PDOException(self::$exception['unrecognized']);
} elseif ($error['code'] == '2005') {
throw new \PDOException(self::$exception['code-2005']);
} elseif ($error['code'] == '2002') {
throw new \PDOException(self::$exception['code-2002']);
} elseif ($error['code'] == '1044') {
throw new \PDOException(sprintf(self::$exception['code-1044'], $user));
} elseif ($error['code'] == '1045') {
throw new \PDOException(sprintf(self::$exception['code-1045'], $user, $pass));
} else {
throw $e;
}
}
} catch (\PDOException $e) {
self::stackTrace($e);
}
}