@@ -27,18 +27,18 @@ public static function makeInsertQuery(string $table, &$dataset, bool $pretty =
27
27
28
28
foreach ($ dataset as $ index => $ value ) {
29
29
if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
30
- $ insert_fields [] = "{$ pretty } ` {$ index }` = NOW() " ;
30
+ $ insert_fields [] = "{$ pretty } {$ index } = NOW() " ;
31
31
unset($ dataset [ $ index ]);
32
32
continue ;
33
33
}
34
34
35
35
if (\strtoupper (\trim ($ value )) === 'UUID() ' ) {
36
- $ insert_fields [] = "\r\n {$ index } = UUID() " ;
36
+ $ insert_fields [] = "{ $ pretty } {$ index } = UUID() " ;
37
37
unset($ dataset [$ index ]);
38
38
continue ;
39
39
}
40
40
41
- $ insert_fields [] = "{$ pretty } ` {$ index }` = : {$ index }" ;
41
+ $ insert_fields [] = "{$ pretty } {$ index } = : {$ index }" ;
42
42
}
43
43
44
44
$ query .= \implode (', ' , $ insert_fields ) . ' ; ' ;
@@ -64,11 +64,11 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
64
64
$ set = [];
65
65
$ pretty = $ pretty ? "\r\n" : '' ;
66
66
67
- $ query = "UPDATE ` {$ table }` SET " ;
67
+ $ query = "UPDATE {$ table } SET " ;
68
68
69
69
foreach ($ dataset as $ index => $ value ) {
70
70
if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
71
- $ set [] = "{$ pretty } ` {$ index }` = NOW() " ;
71
+ $ set [] = "{$ pretty } {$ index } = NOW() " ;
72
72
unset($ dataset [ $ index ]);
73
73
continue ;
74
74
}
@@ -79,7 +79,7 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
79
79
continue ;
80
80
}
81
81
82
- $ set [] = "{$ pretty } ` {$ index }` = : {$ index }" ;
82
+ $ set [] = "{$ pretty } {$ index } = : {$ index }" ;
83
83
}
84
84
85
85
$ query .= \implode (', ' , $ set );
@@ -117,11 +117,11 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
117
117
118
118
$ pretty = $ pretty ? "\r\n" : '' ;
119
119
120
- $ query = "REPLACE ` {$ table }` SET " ;
120
+ $ query = "REPLACE {$ table } SET " ;
121
121
122
122
foreach ($ dataset as $ index => $ value ) {
123
123
if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
124
- $ fields [] = "` {$ index }` = NOW() " ;
124
+ $ fields [] = "{$ index } = NOW() " ;
125
125
unset($ dataset [ $ index ]);
126
126
continue ;
127
127
}
@@ -132,7 +132,7 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
132
132
continue ;
133
133
}
134
134
135
- $ fields [] = " ` {$ index }` = : {$ index } " ;
135
+ $ fields [] = " {$ index } = : {$ index } " ;
136
136
}
137
137
138
138
$ query .= \implode (', ' , $ fields );
@@ -147,16 +147,19 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
147
147
*
148
148
* @param string $table
149
149
* @param array $dataset
150
+ * @param bool $pretty
150
151
* @return string
151
152
*/
152
- public static function buildReplaceQuery (string $ table , array $ dataset ):string
153
+ public static function buildReplaceQuery (string $ table , array $ dataset, bool $ pretty = true ):string
153
154
{
155
+ $ pretty = $ pretty ? "\r\n" : '' ;
156
+
154
157
$ dataset_keys = \array_keys ($ dataset );
155
158
156
- $ query = "REPLACE INTO ` {$ table }` ( " ;
159
+ $ query = "REPLACE INTO {$ table } ( " ;
157
160
158
161
$ query .= \implode (', ' , \array_map (function ($ i ){
159
- return "` {$ i }` " ;
162
+ return "{$ i }" ;
160
163
}, $ dataset_keys ));
161
164
162
165
$ query .= " ) VALUES ( " ;
@@ -174,14 +177,17 @@ public static function buildReplaceQuery(string $table, array $dataset):string
174
177
* @param string $table
175
178
* @param array $dataset
176
179
* @param null $where_condition - строка условия без WHERE ('x=0 AND y=0' ) или массив условий ['x=0', 'y=0']
180
+ * @param bool $pretty
177
181
* @return string
178
182
*/
179
- public static function buildUpdateQuery (string $ table , array $ dataset = [], $ where_condition = null ):string
183
+ public static function buildUpdateQuery (string $ table , array $ dataset = [], $ where_condition = null , bool $ pretty = true ):string
180
184
{
181
- $ query = "UPDATE ` {$ table }` SET " ;
185
+ $ pretty = $ pretty ? "\r\n" : '' ;
186
+
187
+ $ query = "UPDATE {$ table } SET " ;
182
188
183
- $ query .= \implode (', ' , \array_map (function ($ key , $ value ){
184
- return "\r\n ` { $ key }` = : {$ key }" ;
189
+ $ query .= \implode (', ' , \array_map (function ($ key , $ value ) use ( $ pretty ) {
190
+ return "{ $ pretty } { $ key } = : {$ key }" ;
185
191
}, \array_keys ($ dataset ), $ dataset ));
186
192
187
193
$ where
@@ -209,12 +215,12 @@ public static function buildUpdateQuery(string $table, array $dataset = [], $whe
209
215
*/
210
216
public static function buildReplaceQueryMVA (string $ table , array $ dataset , array $ mva_attributes ):array
211
217
{
212
- $ query = "REPLACE INTO ` {$ table }` ( " ;
218
+ $ query = "REPLACE INTO {$ table } ( " ;
213
219
214
220
$ dataset_keys = \array_keys ($ dataset );
215
221
216
222
$ query .= \implode (', ' , \array_map ( static function ($ i ){
217
- return "` {$ i }` " ;
223
+ return "{$ i }" ;
218
224
}, $ dataset_keys ));
219
225
220
226
$ query .= " ) VALUES ( " ;
0 commit comments