@@ -210,9 +210,8 @@ public function result() {
210210 return $ this ->result ;
211211 }
212212
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 " );
216215 }
217216
218217 public function fetch ($ flags = 512 ) {
@@ -221,8 +220,6 @@ public function fetch($flags = 512) {
221220 }
222221
223222 public function deleteDB ($ db , $ flags ) {
224- if ($ db ==$ this ->db )
225- throw new SmysqlException ("(deleteDB): You can’t delete current database " );
226223 if ($ this ->query ("DROP DATABASE ` $ db` " , $ flags , "deleteDB " )) {
227224 return true ;
228225 }
@@ -240,14 +237,18 @@ public function changeDB($newDB) {
240237 $ this ->reload ();
241238 }
242239
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 );
251252 $ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
252253 if (!empty ($ order ))
253254 $ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -256,16 +257,20 @@ public function select($table, $order = "", $cols = ["*"], $limit = NULL, $flags
256257 " , $ flags , "select " );
257258 }
258259
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 " ) {
260261 $ 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 );
261273 $ 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 );
269274 $ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
270275 if (!empty ($ order ))
271276 $ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -274,22 +279,27 @@ public function selectWhere($table, $cond, $order = "", $cols = ["*"], $limit =
274279 " , $ flags , $ name );
275280 }
276281
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 ) {
278283 $ all = !boolval ($ flags & self ::COND_OR );
279284 switch (true ) {
280285 case boolval ($ flags & self ::JOIN_LEFT ): $ jt = "LEFT OUTER " ; break ;
281286 case boolval ($ flags & self ::JOIN_RIGHT ): $ jt = "RIGHT OUTER " ; break ;
282287 case boolval ($ flags & self ::JOIN_FULL ): $ jt = "FULL OUTER " ; break ;
283288 default : $ jt = "INNER " ;
284289 };
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 );
285301 $ 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 );
293303 $ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
294304 if (!empty ($ order ))
295305 $ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -300,23 +310,27 @@ public function selectJoin($table, $join, $on, $order = "", $cols = ["*"], $limi
300310 " , $ flags , "selectJoin " );
301311 }
302312
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 ) {
304314 $ all = !boolval ($ flags & self ::COND_OR );
305315 switch (true ) {
306316 case boolval ($ flags & self ::JOIN_LEFT ): $ jt = "LEFT OUTER " ; break ;
307317 case boolval ($ flags & self ::JOIN_RIGHT ): $ jt = "RIGHT OUTER " ; break ;
308318 case boolval ($ flags & self ::JOIN_FULL ): $ jt = "FULL OUTER " ; break ;
309319 default : $ jt = "INNER " ;
310320 };
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 );
311332 $ onString = $ this ->getCondString ($ on , $ all , true );
312333 $ 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 );
320334 $ limitString = ($ limit ===NULL || $ limit ==="" ) ? "" : " LIMIT " . intval ($ this ->escape ($ limit ));
321335 if (!empty ($ order ))
322336 $ order = " ORDER BY ` " . $ order . "` " . (boolval ($ flags & self ::ORDER_DESC ) ? "DESC " : "ASC " );
@@ -330,7 +344,7 @@ public function selectJoinWhere($table, $join, $on, $cond, $order = "", $cols =
330344
331345 public function exists ($ table , $ cond , $ flags = 129 , $ name = "exists " ) {
332346 $ all = !boolval ($ flags & self ::COND_OR );
333- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags , $ name );
347+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags , $ name );
334348 $ noFetch = !$ this ->fetch ();
335349 return !$ noFetch ;
336350 }
@@ -421,15 +435,15 @@ public function change($table, $name, $newname, $type, $length, $null, $data = "
421435
422436 public function selectAll ($ table , $ flags = 129 ) {
423437 $ r = $ this ->result ;
424- $ this ->select ($ table , "" , [ "* " ] , NULL , $ flags );
438+ $ this ->select ($ table , "" , "* " , NULL , $ flags );
425439 $ f = $ this ->fetch ($ flags | self ::FETCH_ALL );
426440 $ this ->result = $ r ;
427441 return $ f ;
428442 }
429443
430444 public function fetchWhere ($ table , $ cond , $ flags = 129 ) {
431445 $ r = $ this ->result ;
432- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags );
446+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags );
433447 $ f = $ this ->fetch ();
434448 $ this ->result = $ r ;
435449 return $ f ;
@@ -453,7 +467,7 @@ public function read($table, $cond = [], $flags = 129) {
453467 else
454468 return false ;
455469 else {
456- $ this ->selectWhere ($ table , $ cond , "" , [ "* " ] , NULL , $ flags );
470+ $ this ->selectWhere ($ table , $ cond , "" , "* " , NULL , $ flags );
457471 $ f = $ this ->fetch (self ::FETCH_ALL );
458472 };
459473 if ($ f ===new stdClass () && !boolval ($ flags & self ::ALWAYS_ARRAY ))
0 commit comments