private static $db_user = '';
private static $db_pass = '';
private static $db_name = '';
+ private static $db_charset = '';
- public static function connect($serveraddr, $user, $pass, $db) {
+ public static function connect($serveraddr, $user, $pass, $db, $charset = null)
+ {
if (!is_null(self::$db) && self::connected()) {
return true;
}
- $a = get_app();
-
- $stamp1 = microtime(true);
-
// We are storing these values for being able to perform a reconnect
self::$db_serveraddr = $serveraddr;
self::$db_user = $user;
self::$db_pass = $pass;
self::$db_name = $db;
+ self::$db_charset = $charset;
$serveraddr = trim($serveraddr);
$user = trim($user);
$pass = trim($pass);
$db = trim($db);
+ $charset = trim($charset);
if (!(strlen($server) && strlen($user))) {
return false;
$connect .= ";port=".$port;
}
- if (isset($a->config["system"]["db_charset"])) {
- $connect .= ";charset=".$a->config["system"]["db_charset"];
+ if ($charset) {
+ $connect .= ";charset=".$charset;
}
+
try {
self::$db = @new PDO($connect, $user, $pass);
self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
if (!mysqli_connect_errno()) {
self::$connected = true;
- if (isset($a->config["system"]["db_charset"])) {
- self::$db->set_charset($a->config["system"]["db_charset"]);
+ if ($charset) {
+ self::$db->set_charset($charset);
}
}
}
self::$driver = null;
self::$db = null;
}
- $a->save_timestamp($stamp1, "network");
return self::$connected;
}
public static function reconnect() {
self::disconnect();
- $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name);
+ $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
return $ret;
}
$is_alpha = true;
}
}
-
+
if ($is_int && $is_alpha) {
foreach ($value as &$ref) {
if (is_int($ref)) {