@@ -210,9 +210,8 @@ public function result() {
210
210
return $ this ->result ;
211
211
}
212
212
213
- public function charset ($ charset ) {
214
- $ this ->connect ->exec ("SET NAMES " . $ charset );
215
- return $ charset ;
213
+ public function charset ($ charset , $ flags = 0 ) {
214
+ return $ this ->query ("SET NAMES " . $ charset , $ flags , "charset " );
216
215
}
217
216
218
217
public function fetch ($ flags = 512 ) {
@@ -221,8 +220,6 @@ public function fetch($flags = 512) {
221
220
}
222
221
223
222
public function deleteDB ($ db , $ flags ) {
224
- if ($ db ==$ this ->db )
225
- throw new SmysqlException ("(deleteDB): You can’t delete current database " );
226
223
if ($ this ->query ("DROP DATABASE ` $ db` " , $ flags , "deleteDB " )) {
227
224
return true ;
228
225
}
@@ -240,14 +237,18 @@ public function changeDB($newDB) {
240
237
$ this ->reload ();
241
238
}
242
239
243
- public function select ($ table , $ order = "" , $ cols = ["* " ], $ limit = NULL , $ flags = 129 ) {
244
- foreach ($ cols as $ k => $ v ) {
245
- if (gettype ($ k )!="integer " )
246
- $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
247
- elseif ($ v !="* " )
248
- $ cols [$ k ] = "` " . $ v . "` " ;
249
- };
250
- $ colsValue = implode (", " , $ cols );
240
+ public function select ($ table , $ order = "" , $ cols = "* " , $ limit = NULL , $ flags = 129 ) {
241
+ if (is_array ($ cols )) {
242
+ foreach ($ cols as $ k => $ v ) {
243
+ if (gettype ($ k )!="integer " )
244
+ $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
245
+ else
246
+ $ cols [$ k ] = "` " . $ v . "` " ;
247
+ };
248
+ $ colsValue = implode (", " , $ cols );
249
+ }
250
+ else
251
+ $ colsValue = strval ($ cols );
251
252
$ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
252
253
if (!empty ($ order ))
253
254
$ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -256,16 +257,20 @@ public function select($table, $order = "", $cols = ["*"], $limit = NULL, $flags
256
257
" , $ flags , "select " );
257
258
}
258
259
259
- public function selectWhere ($ table , $ cond , $ order = "" , $ cols = [ "* " ] , $ limit = NULL , $ flags = 129 , $ name = "selectWhere " ) {
260
+ public function selectWhere ($ table , $ cond , $ order = "" , $ cols = "* " , $ limit = NULL , $ flags = 129 , $ name = "selectWhere " ) {
260
261
$ all = !boolval ($ cond & self ::COND_OR );
262
+ if (is_array ($ cols )) {
263
+ foreach ($ cols as $ k => $ v ) {
264
+ if (gettype ($ k )!="integer " )
265
+ $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
266
+ else
267
+ $ cols [$ k ] = "` " . $ v . "` " ;
268
+ };
269
+ $ colsValue = implode (", " , $ cols );
270
+ }
271
+ else
272
+ $ colsValue = strval ($ cols );
261
273
$ condString = $ this ->getCondString ($ cond , $ all );
262
- foreach ($ cols as $ k => $ v ) {
263
- if (gettype ($ k )!="integer " )
264
- $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
265
- elseif ($ v !="* " )
266
- $ cols [$ k ] = "` " . $ v . "` " ;
267
- };
268
- $ colsValue = implode (", " , $ cols );
269
274
$ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
270
275
if (!empty ($ order ))
271
276
$ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -274,22 +279,27 @@ public function selectWhere($table, $cond, $order = "", $cols = ["*"], $limit =
274
279
" , $ flags , $ name );
275
280
}
276
281
277
- public function selectJoin ($ table , $ join , $ on , $ order = "" , $ cols = [ "* " ] , $ limit = NULL , $ flags = 133 ) {
282
+ public function selectJoin ($ table , $ join , $ on , $ order = "" , $ cols = "* " , $ limit = NULL , $ flags = 133 ) {
278
283
$ all = !boolval ($ flags & self ::COND_OR );
279
284
switch (true ) {
280
285
case boolval ($ flags & self ::JOIN_LEFT ): $ jt = "LEFT OUTER " ; break ;
281
286
case boolval ($ flags & self ::JOIN_RIGHT ): $ jt = "RIGHT OUTER " ; break ;
282
287
case boolval ($ flags & self ::JOIN_FULL ): $ jt = "FULL OUTER " ; break ;
283
288
default : $ jt = "INNER " ;
284
289
};
290
+ if (is_array ($ cols )) {
291
+ foreach ($ cols as $ k => $ v ) {
292
+ if (gettype ($ k )!="integer " )
293
+ $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
294
+ else
295
+ $ cols [$ k ] = "` " . $ v . "` " ;
296
+ };
297
+ $ colsValue = implode (", " , $ cols );
298
+ }
299
+ else
300
+ $ colsValue = strval ($ cols );
285
301
$ onString = $ this ->getCondString ($ on , $ all , true );
286
- foreach ($ cols as $ k => $ v ) {
287
- if (gettype ($ k )!="integer " )
288
- $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
289
- elseif ($ v !="* " )
290
- $ cols [$ k ] = "` " . $ v . "` " ;
291
- };
292
- $ colsValue = implode (", " , $ cols );
302
+ $ condString = $ this ->getCondString ($ cond , $ all );
293
303
$ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
294
304
if (!empty ($ order ))
295
305
$ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -300,23 +310,27 @@ public function selectJoin($table, $join, $on, $order = "", $cols = ["*"], $limi
300
310
" , $ flags , "selectJoin " );
301
311
}
302
312
303
- public function selectJoinWhere ($ table , $ join , $ on , $ cond , $ order = "" , $ cols = [ "* " ] , $ limit = NULL , $ flags = 133 ) {
313
+ public function selectJoinWhere ($ table , $ join , $ on , $ cond , $ order = "" , $ cols = "* " , $ limit = NULL , $ flags = 133 ) {
304
314
$ all = !boolval ($ flags & self ::COND_OR );
305
315
switch (true ) {
306
316
case boolval ($ flags & self ::JOIN_LEFT ): $ jt = "LEFT OUTER " ; break ;
307
317
case boolval ($ flags & self ::JOIN_RIGHT ): $ jt = "RIGHT OUTER " ; break ;
308
318
case boolval ($ flags & self ::JOIN_FULL ): $ jt = "FULL OUTER " ; break ;
309
319
default : $ jt = "INNER " ;
310
320
};
321
+ if (is_array ($ cols )) {
322
+ foreach ($ cols as $ k => $ v ) {
323
+ if (gettype ($ k )!="integer " )
324
+ $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
325
+ else
326
+ $ cols [$ k ] = "` " . $ v . "` " ;
327
+ };
328
+ $ colsValue = implode (", " , $ cols );
329
+ }
330
+ else
331
+ $ colsValue = strval ($ cols );
311
332
$ onString = $ this ->getCondString ($ on , $ all , true );
312
333
$ condString = $ this ->getCondString ($ cond , $ all );
313
- foreach ($ cols as $ k => $ v ) {
314
- if (gettype ($ k )!="integer " )
315
- $ cols [$ k ] = "` " . $ v . "` " . " AS " . "` " . $ k . "` " ;
316
- elseif ($ v !="* " )
317
- $ cols [$ k ] = "` " . $ v . "` " ;
318
- };
319
- $ colsValue = implode (", " , $ cols );
320
334
$ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
321
335
if (!empty ($ order ))
322
336
$ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -330,7 +344,7 @@ public function selectJoinWhere($table, $join, $on, $cond, $order = "", $cols =
330
344
331
345
public function exists ($ table , $ cond , $ flags = 129 , $ name = "exists " ) {
332
346
$ all = !boolval ($ flags & self ::COND_OR );
333
- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags , $ name );
347
+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags , $ name );
334
348
$ noFetch = !$ this ->fetch ();
335
349
return !$ noFetch ;
336
350
}
@@ -421,15 +435,15 @@ public function change($table, $name, $newname, $type, $length, $null, $data = "
421
435
422
436
public function selectAll ($ table , $ flags = 129 ) {
423
437
$ r = $ this ->result ;
424
- $ this ->select ($ table , "" , [ "* " ] , NULL , $ flags );
438
+ $ this ->select ($ table , "" , "* " , NULL , $ flags );
425
439
$ f = $ this ->fetch ($ flags | self ::FETCH_ALL );
426
440
$ this ->result = $ r ;
427
441
return $ f ;
428
442
}
429
443
430
444
public function fetchWhere ($ table , $ cond , $ flags = 129 ) {
431
445
$ r = $ this ->result ;
432
- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags );
446
+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags );
433
447
$ f = $ this ->fetch ();
434
448
$ this ->result = $ r ;
435
449
return $ f ;
@@ -453,7 +467,7 @@ public function read($table, $cond = [], $flags = 129) {
453
467
else
454
468
return false ;
455
469
else {
456
- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags );
470
+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags );
457
471
$ f = $ this ->fetch (self ::FETCH_ALL );
458
472
};
459
473
if ($ f ===new stdClass () && !boolval ($ flags & self ::ALWAYS_ARRAY ))
0 commit comments