|
@@ -19,7 +19,7 @@ class Db
|
|
|
|
|
|
private function __construct()
|
|
|
{
|
|
|
- if (!extension_loaded('mysqli')){
|
|
|
+ if (!extension_loaded('mysqli')) {
|
|
|
throw_exception("Db Error: mysqli is not install");
|
|
|
}
|
|
|
}
|
|
@@ -292,7 +292,8 @@ class Db
|
|
|
* @param array $insert_array 待插入数据
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public static function insertAll($table_name, $insert_array=array(), $host = 'master'){
|
|
|
+ public static function insertAll($table_name, $insert_array=array(), $host = 'master')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
if (!is_array($insert_array[0])) return false;
|
|
|
$fields = array_keys($insert_array[0]);
|
|
@@ -322,7 +323,8 @@ class Db
|
|
|
* @param string $where 执行条件
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function update($table_name, $update_array = array(), $where = '', $host = 'master'){
|
|
|
+ public static function update($table_name, $update_array = array(), $where = '', $host = 'master')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
if (!is_array($update_array)) return false;
|
|
|
$string_value = '';
|
|
@@ -360,7 +362,8 @@ class Db
|
|
|
* @param string $where 执行条件
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function delete($table_name, $where = '', $host = 'master'){
|
|
|
+ public static function delete($table_name, $where = '', $host = 'master')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
if (trim($where) != ''){
|
|
|
if (strtoupper(substr(trim($where),0,5)) != 'WHERE'){
|
|
@@ -400,7 +403,8 @@ class Db
|
|
|
* @param string $fields
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function getRow($param, $fields = '*', $host = 'slave'){
|
|
|
+ public static function getRow($param, $fields = '*', $host = 'slave')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
$table = $param['table'];
|
|
|
$wfield = $param['field'];
|
|
@@ -429,7 +433,8 @@ class Db
|
|
|
* @param array $replace_array 待更新的数据
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function replace($table_name, $replace_array = array(), $host = 'master'){
|
|
|
+ public static function replace($table_name, $replace_array = array(), $host = 'master')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
if (!empty($replace_array))
|
|
|
{
|
|
@@ -453,7 +458,8 @@ class Db
|
|
|
* @param $condition mixed 查询条件,可以为空,也可以为数组或字符串
|
|
|
* @return int
|
|
|
*/
|
|
|
- public static function getCount($table, $condition = null, $host = 'slave'){
|
|
|
+ public static function getCount($table, $condition = null, $host = 'slave')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
|
|
|
if (!empty($condition) && is_array($condition)){
|
|
@@ -583,7 +589,8 @@ class Db
|
|
|
return "'".$value."'";
|
|
|
}
|
|
|
|
|
|
- public static function beginTransaction($host = 'master'){
|
|
|
+ public static function beginTransaction($host = 'master')
|
|
|
+ {
|
|
|
self::connect($host);
|
|
|
if (self::$iftransacte){
|
|
|
self::$link[$host]->autocommit(false);//关闭自动提交
|
|
@@ -591,7 +598,18 @@ class Db
|
|
|
self::$iftransacte = false;
|
|
|
}
|
|
|
|
|
|
- public static function commit($host = 'master'){
|
|
|
+// public static function start_transaction($host = 'master')
|
|
|
+// {
|
|
|
+// self::connect($host);
|
|
|
+// if (self::$iftransacte){
|
|
|
+// self::$link[$host]->autocommit(false);//关闭自动提交
|
|
|
+// self::$iftransacte = false;
|
|
|
+// self::$link[$host]->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ public static function commit($host = 'master')
|
|
|
+ {
|
|
|
if (!self::$iftransacte){
|
|
|
$result = self::$link[$host]->commit();
|
|
|
self::$link[$host]->autocommit(true);//开启自动提交
|
|
@@ -600,7 +618,8 @@ class Db
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function rollback($host = 'master'){
|
|
|
+ public static function rollback($host = 'master')
|
|
|
+ {
|
|
|
if (!self::$iftransacte){
|
|
|
$result = self::$link[$host]->rollback();
|
|
|
self::$link[$host]->autocommit(true);
|
|
@@ -609,8 +628,8 @@ class Db
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function affected_rows($host = 'master') {
|
|
|
- self::connect($host);
|
|
|
+ public static function affected_rows($host = 'master')
|
|
|
+ {
|
|
|
return self::$link[$host]->affected_rows;
|
|
|
}
|
|
|
}
|