|
@@ -8,19 +8,23 @@
|
|
|
|
|
|
|
|
|
defined('InShopNC') or exit('Access Invalid!');
|
|
|
-class Db{
|
|
|
-
|
|
|
+class Db
|
|
|
+{
|
|
|
private static $link = array();
|
|
|
private static $iftransacte = true;
|
|
|
|
|
|
+ private static $connect_time = 0;
|
|
|
+
|
|
|
private function __construct(){
|
|
|
if (!extension_loaded('mysqli')){
|
|
|
throw_exception("Db Error: mysqli is not install");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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 (is_object(self::$link['slave'])){
|
|
@@ -39,7 +43,7 @@ class Db{
|
|
|
}
|
|
|
|
|
|
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");
|
|
|
|
|
|
switch (strtoupper($conf['dbcharset']))
|
|
@@ -78,6 +82,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') {
|
|
|
if (is_object(self::$link[$host])) {
|
|
|
// if (is_object(self::$link[$host]) && !self::$link[$host]->ping()) {
|