@@ -27,18 +27,18 @@ public static function makeInsertQuery(string $table, &$dataset, bool $pretty =
2727
2828 foreach ($ dataset as $ index => $ value ) {
2929 if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
30- $ insert_fields [] = "{$ pretty } ` {$ index }` = NOW() " ;
30+ $ insert_fields [] = "{$ pretty } {$ index } = NOW() " ;
3131 unset($ dataset [ $ index ]);
3232 continue ;
3333 }
3434
3535 if (\strtoupper (\trim ($ value )) === 'UUID() ' ) {
36- $ insert_fields [] = "\r\n {$ index } = UUID() " ;
36+ $ insert_fields [] = "{ $ pretty } {$ index } = UUID() " ;
3737 unset($ dataset [$ index ]);
3838 continue ;
3939 }
4040
41- $ insert_fields [] = "{$ pretty } ` {$ index }` = : {$ index }" ;
41+ $ insert_fields [] = "{$ pretty } {$ index } = : {$ index }" ;
4242 }
4343
4444 $ query .= \implode (', ' , $ insert_fields ) . ' ; ' ;
@@ -64,11 +64,11 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
6464 $ set = [];
6565 $ pretty = $ pretty ? "\r\n" : '' ;
6666
67- $ query = "UPDATE ` {$ table }` SET " ;
67+ $ query = "UPDATE {$ table } SET " ;
6868
6969 foreach ($ dataset as $ index => $ value ) {
7070 if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
71- $ set [] = "{$ pretty } ` {$ index }` = NOW() " ;
71+ $ set [] = "{$ pretty } {$ index } = NOW() " ;
7272 unset($ dataset [ $ index ]);
7373 continue ;
7474 }
@@ -79,7 +79,7 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
7979 continue ;
8080 }
8181
82- $ set [] = "{$ pretty } ` {$ index }` = : {$ index }" ;
82+ $ set [] = "{$ pretty } {$ index } = : {$ index }" ;
8383 }
8484
8585 $ query .= \implode (', ' , $ set );
@@ -117,11 +117,11 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
117117
118118 $ pretty = $ pretty ? "\r\n" : '' ;
119119
120- $ query = "REPLACE ` {$ table }` SET " ;
120+ $ query = "REPLACE {$ table } SET " ;
121121
122122 foreach ($ dataset as $ index => $ value ) {
123123 if (\strtoupper (\trim ($ value )) === 'NOW() ' ) {
124- $ fields [] = "` {$ index }` = NOW() " ;
124+ $ fields [] = "{$ index } = NOW() " ;
125125 unset($ dataset [ $ index ]);
126126 continue ;
127127 }
@@ -132,7 +132,7 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
132132 continue ;
133133 }
134134
135- $ fields [] = " ` {$ index }` = : {$ index } " ;
135+ $ fields [] = " {$ index } = : {$ index } " ;
136136 }
137137
138138 $ query .= \implode (', ' , $ fields );
@@ -147,16 +147,19 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
147147 *
148148 * @param string $table
149149 * @param array $dataset
150+ * @param bool $pretty
150151 * @return string
151152 */
152- public static function buildReplaceQuery (string $ table , array $ dataset ):string
153+ public static function buildReplaceQuery (string $ table , array $ dataset, bool $ pretty = true ):string
153154 {
155+ $ pretty = $ pretty ? "\r\n" : '' ;
156+
154157 $ dataset_keys = \array_keys ($ dataset );
155158
156- $ query = "REPLACE INTO ` {$ table }` ( " ;
159+ $ query = "REPLACE INTO {$ table } ( " ;
157160
158161 $ query .= \implode (', ' , \array_map (function ($ i ){
159- return "` {$ i }` " ;
162+ return "{$ i }" ;
160163 }, $ dataset_keys ));
161164
162165 $ query .= " ) VALUES ( " ;
@@ -174,14 +177,17 @@ public static function buildReplaceQuery(string $table, array $dataset):string
174177 * @param string $table
175178 * @param array $dataset
176179 * @param null $where_condition - строка условия без WHERE ('x=0 AND y=0' ) или массив условий ['x=0', 'y=0']
180+ * @param bool $pretty
177181 * @return string
178182 */
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
180184 {
181- $ query = "UPDATE ` {$ table }` SET " ;
185+ $ pretty = $ pretty ? "\r\n" : '' ;
186+
187+ $ query = "UPDATE {$ table } SET " ;
182188
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 }" ;
185191 }, \array_keys ($ dataset ), $ dataset ));
186192
187193 $ where
@@ -209,12 +215,12 @@ public static function buildUpdateQuery(string $table, array $dataset = [], $whe
209215 */
210216 public static function buildReplaceQueryMVA (string $ table , array $ dataset , array $ mva_attributes ):array
211217 {
212- $ query = "REPLACE INTO ` {$ table }` ( " ;
218+ $ query = "REPLACE INTO {$ table } ( " ;
213219
214220 $ dataset_keys = \array_keys ($ dataset );
215221
216222 $ query .= \implode (', ' , \array_map ( static function ($ i ){
217- return "` {$ i }` " ;
223+ return "{$ i }" ;
218224 }, $ dataset_keys ));
219225
220226 $ query .= " ) VALUES ( " ;
0 commit comments