|
@@ -99,12 +99,7 @@ class DbPool { |
|
@@ -99,12 +99,7 @@ class DbPool { |
99
|
|
99
|
|
100
|
$sql = "update `{$table}` set ".dbUpdate($data). " where ".$where;
|
100
|
$sql = "update `{$table}` set ".dbUpdate($data). " where ".$where;
|
101
|
|
101
|
|
102
|
- // 如果存储的值是数组,就json一次
|
|
|
103
|
- foreach ($data as $k=>$datum){
|
|
|
104
|
- if(is_array($datum)){
|
|
|
105
|
- $data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE);
|
|
|
106
|
- }
|
|
|
107
|
- }
|
102
|
+ $data = $this->getData($data);
|
108
|
|
103
|
|
109
|
$query = $this->query([$sql,$data]);
|
104
|
$query = $this->query([$sql,$data]);
|
110
|
if($query){
|
105
|
if($query){
|
|
@@ -115,6 +110,26 @@ class DbPool { |
|
@@ -115,6 +110,26 @@ class DbPool { |
115
|
|
110
|
|
116
|
|
111
|
|
117
|
/**
|
112
|
/**
|
|
|
113
|
+ * 在更新/插入时处理数据
|
|
|
114
|
+ * @param $data
|
|
|
115
|
+ * @return mixed
|
|
|
116
|
+ * @author:dc
|
|
|
117
|
+ * @time 2023/2/18 14:50
|
|
|
118
|
+ */
|
|
|
119
|
+ private function getData($data){
|
|
|
120
|
+ // 如果存储的值是数组,就json一次
|
|
|
121
|
+ foreach ($data as $k=>$datum){
|
|
|
122
|
+ if(is_array($datum)){
|
|
|
123
|
+ $data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE);
|
|
|
124
|
+ }elseif ($datum === null){
|
|
|
125
|
+ $data[$k] = '';
|
|
|
126
|
+ }
|
|
|
127
|
+ }
|
|
|
128
|
+ return $data;
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+
|
|
|
132
|
+ /**
|
118
|
* 插入数据
|
133
|
* 插入数据
|
119
|
* @param string $table
|
134
|
* @param string $table
|
120
|
* @param array $data
|
135
|
* @param array $data
|
|
@@ -131,12 +146,7 @@ class DbPool { |
|
@@ -131,12 +146,7 @@ class DbPool { |
131
|
|
146
|
|
132
|
$sql = "insert into `{$table}` set ".dbUpdate($data);
|
147
|
$sql = "insert into `{$table}` set ".dbUpdate($data);
|
133
|
|
148
|
|
134
|
- // 如果存储的值是数组,就json一次
|
|
|
135
|
- foreach ($data as $k=>$datum){
|
|
|
136
|
- if(is_array($datum)){
|
|
|
137
|
- $data[$k] = json_encode($datum,JSON_UNESCAPED_UNICODE);
|
|
|
138
|
- }
|
|
|
139
|
- }
|
149
|
+ $data = $this->getData($data);
|
140
|
|
150
|
|
141
|
$query = $this->query([$sql,$data]);
|
151
|
$query = $this->query([$sql,$data]);
|
142
|
|
152
|
|