|
@@ -11,7 +11,6 @@ defined('InShopNC') or exit('Access Invalid!');
|
|
|
class Db{
|
|
|
|
|
|
private static $link = array();
|
|
|
-
|
|
|
private static $iftransacte = true;
|
|
|
|
|
|
private function __construct(){
|
|
@@ -20,22 +19,31 @@ class Db{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static function connect($host = 'slave'){
|
|
|
- if (C('db.master') == C('db.slave')){
|
|
|
+ private static function connect($host = 'slave')
|
|
|
+ {
|
|
|
+ if (C('db.master') == C('db.slave'))
|
|
|
+ {
|
|
|
if (is_object(self::$link['slave'])){
|
|
|
- self::$link['master'] = & self::$link['slave'];return ;
|
|
|
+ self::$link['master'] = & self::$link['slave'];
|
|
|
+ return ;
|
|
|
}elseif (is_object(self::$link['master'])){
|
|
|
- self::$link['slave'] = & self::$link['master'];return ;
|
|
|
+ self::$link['slave'] = & self::$link['master'];
|
|
|
+ return ;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (!in_array($host,array('master','slave'))) $host = 'slave';
|
|
|
$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']);
|
|
|
|
|
|
if (mysqli_connect_errno()) throw_exception("Db Error: database connect failed");
|
|
|
|
|
|
- switch (strtoupper($conf['dbcharset'])){
|
|
|
+ switch (strtoupper($conf['dbcharset']))
|
|
|
+ {
|
|
|
case 'UTF-8':
|
|
|
$query_string = "
|
|
|
SET CHARACTER_SET_CLIENT = utf8,
|
|
@@ -65,7 +73,7 @@ class Db{
|
|
|
throw_exception($error);
|
|
|
}
|
|
|
//进行编码声明
|
|
|
- if (!self::$link[$host]->query($query_string)){
|
|
|
+ if (!self::$link[$host]->query($query_string)) {
|
|
|
throw_exception("Db Error: ".mysqli_error(self::$link[$host]));
|
|
|
}
|
|
|
}
|