|
@@ -14,6 +14,8 @@ class Db{
|
|
|
|
|
|
private static $iftransacte = true;
|
|
private static $iftransacte = true;
|
|
|
|
|
|
|
|
+ private static $connect_time = 0;
|
|
|
|
+
|
|
private function __construct(){
|
|
private function __construct(){
|
|
if (!extension_loaded('mysqli')){
|
|
if (!extension_loaded('mysqli')){
|
|
throw_exception("Db Error: mysqli is not install");
|
|
throw_exception("Db Error: mysqli is not install");
|
|
@@ -21,6 +23,9 @@ class Db{
|
|
}
|
|
}
|
|
|
|
|
|
private static function connect($host = 'slave'){
|
|
private static function connect($host = 'slave'){
|
|
|
|
+ if((time() - self::$connect_time > 1800) && defined('MOBILE_SERVER') && self::$connect_time > 0){
|
|
|
|
+ self::closeLink();
|
|
|
|
+ }
|
|
if (C('db.master') == C('db.slave')){
|
|
if (C('db.master') == C('db.slave')){
|
|
if (is_object(self::$link['slave'])){
|
|
if (is_object(self::$link['slave'])){
|
|
self::$link['master'] = & self::$link['slave'];return ;
|
|
self::$link['master'] = & self::$link['slave'];return ;
|
|
@@ -32,7 +37,7 @@ class Db{
|
|
$conf = C('db.'.$host);
|
|
$conf = C('db.'.$host);
|
|
if (is_object(self::$link[$host])) return;
|
|
if (is_object(self::$link[$host])) return;
|
|
self::$link[$host] = @new mysqli($conf['dbhost'], $conf['dbuser'], $conf['dbpwd'], $conf['dbname'], $conf['dbport']);
|
|
self::$link[$host] = @new mysqli($conf['dbhost'], $conf['dbuser'], $conf['dbpwd'], $conf['dbname'], $conf['dbport']);
|
|
-
|
|
|
|
|
|
+ self::$connect_time = time();
|
|
if (mysqli_connect_errno()) throw_exception("Db Error: database connect failed");
|
|
if (mysqli_connect_errno()) throw_exception("Db Error: database connect failed");
|
|
|
|
|
|
switch (strtoupper($conf['dbcharset'])){
|
|
switch (strtoupper($conf['dbcharset'])){
|
|
@@ -70,6 +75,14 @@ class Db{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static function closeLink(){
|
|
|
|
+ foreach(self::$link as $db){
|
|
|
|
+ if(is_object($db)){
|
|
|
|
+ mysqli_close($db);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static function ping($host = 'master') {
|
|
public static function ping($host = 'master') {
|
|
if (is_object(self::$link[$host])) {
|
|
if (is_object(self::$link[$host])) {
|
|
// if (is_object(self::$link[$host]) && !self::$link[$host]->ping()) {
|
|
// if (is_object(self::$link[$host]) && !self::$link[$host]->ping()) {
|