@@ -40,7 +40,7 @@ public function connect($dbname, $hostname='localhost', $username='root', $passw
4040 die ("Failed to connect to MySQL: " . $ this ->dbcon ->connect_err );
4141 }
4242 }
43-
43+
4444 if (empty ($ charset )) $ charset = 'utf8 ' ;
4545 if ($ this ->dbcon )
4646 $ this ->dbcon ->set_charset ($ charset );
@@ -60,7 +60,7 @@ public function exec($sql) {
6060
6161 public function fetch ($ res , $ callback =null ) {
6262 $ result = array ();
63-
63+
6464 $ callback_is = 0 ;
6565 if (is_callable ($ callback ))
6666 $ callback_is = 1 ;
@@ -80,7 +80,7 @@ public function fetch($res, $callback=null) {
8080 $ data ->$ field = $ func ($ data ->$ field , $ data );
8181 }
8282 }
83-
83+
8484 if (count ($ this ->_joinFields ) > 0 ) {
8585 reset ($ this ->_joinFields );
8686 while (list ($ field , $ join ) = each ($ this ->_joinFields )) {
@@ -93,18 +93,18 @@ public function fetch($res, $callback=null) {
9393 $ dataJoin ->$ realField = $ data ->$ field ;
9494 unset($ data ->$ field );
9595
96-
96+
9797 $ data ->$ modelJoin = $ dataJoin ;
9898 }
9999 }
100-
100+
101101 $ result [] = $ data ;
102102 } else
103103 $ result [] = $ data ;
104104 }
105105
106106 $ res ->close ();
107-
107+
108108 return $ result ;
109109 }
110110
@@ -196,7 +196,7 @@ public function update($table, $id, $data) {
196196
197197 $ fieldsValues = implode (', ' , $ fieldsValues );
198198 $ query = "UPDATE ` $ table` SET $ fieldsValues $ where " ;
199-
199+
200200 return $ this ->exec ($ query );
201201 }
202202
@@ -256,7 +256,7 @@ public function find($table, $condition=array(), $limit=array(), $order_by=array
256256 $ condition ['select ' ][] = array ("$ join [1 ]. $ field ->name " , 'as ' =>"__ $ join [1 ]_ $ field ->name " );
257257 }
258258 }
259-
259+
260260 reset ($ condition ['join ' ]);
261261 }
262262
@@ -275,8 +275,8 @@ public function find($table, $condition=array(), $limit=array(), $order_by=array
275275 $ ret = $ this ->fetch ($ res , $ callback );
276276 } else
277277 echo $ this ->dbcon ->error ;
278-
279-
278+
279+
280280 return $ ret ;
281281 }
282282
@@ -296,8 +296,8 @@ public function fields($table) {
296296 $ res ->close ();
297297 } else
298298 echo $ this ->dbcon ->error ;
299- }
300-
299+ }
300+
301301 return $ this ->_fields ;
302302 }
303303
@@ -349,7 +349,7 @@ public static function select($list) {
349349 }
350350 }
351351 }
352-
352+
353353 $ ret = implode (', ' , $ select ).' ' ;
354354 }
355355
@@ -365,22 +365,22 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
365365
366366 if (is_array ($ list ) && count ($ list ) > 0 ) {
367367 while (list ($ idx , $ wherelist ) = each ($ list )) {
368-
368+
369369 //sub operator
370370 if ( is_string ($ idx ) && in_array ($ idx , $ opt )) {
371371 $ where [$ idx ][] .= '( ' .self ::where ($ dbcon , $ wherelist , $ idx , $ idx_where +1 , $ idx ).') ' ;
372372 $ optrow [] = $ idx ;
373373 //logical
374374 } elseif (is_array ($ wherelist )) {
375-
375+
376376 if (count ($ wherelist ) == 1 && isset ($ wherelist [0 ])) {
377377 $ where [$ group ][] = $ wherelist [0 ];
378378 } else {
379379 $ id_step = 0 ;
380380 while (list ($ cond , $ val ) = each ($ wherelist )) {
381381 // if Count item 1
382382 if (count ($ wherelist ) == 1 ) {
383-
383+
384384 for ( $ i =0 ; $ i <= substr_count ($ cond , '? ' ); $ i ++) {
385385 $ pos = strpos ($ cond , '? ' );
386386 $ tmp = substr ($ cond , 0 , $ pos );
@@ -392,7 +392,7 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
392392 $ where [$ group ][] = $ cond ;
393393 // if Count item 2
394394 } elseif (count ($ wherelist ) == 2 ) {
395-
395+
396396 if (is_array ($ val )) {
397397 while (list ($ condkey , $ condval ) = each ($ val )) {
398398 for ( $ i =0 ; $ i <= substr_count ($ cond , '? ' ); $ i ++) {
@@ -437,11 +437,15 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
437437 }
438438 } else {
439439 if ($ id_step == 0 ) {
440- $ val = explode ('. ' , $ val );
441- if (count ($ val ) > 1 )
442- $ val = "` $ val [0 ]`.` $ val [1 ]` " ;
443- else
444- $ val = "` $ val [0 ]` " ;
440+ if (is_array ($ val )) {
441+ $ val = $ val [0 ];
442+ } else {
443+ $ val = explode ('. ' , $ val );
444+ if (count ($ val ) > 1 )
445+ $ val = "` $ val [0 ]`.` $ val [1 ]` " ;
446+ else
447+ $ val = "` $ val [0 ]` " ;
448+ }
445449
446450 $ condfield = $ val ;
447451 $ id_step ++;
@@ -471,7 +475,7 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
471475 $ cond = $ val ;
472476 }
473477 }
474-
478+
475479 $ where [$ group ][] = $ condfield .$ condopt .$ cond ;
476480 $ condfield = '' ;
477481 }
@@ -485,7 +489,7 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
485489 $ ret = ' WHERE ' ;
486490
487491 if (count ($ optrow ) > 0 ) {
488-
492+
489493 while (list ($ id , $ opt ) = each ($ optrow )) {
490494 $ wherestr .= implode (' ' .strtoupper ($ opt ).' ' , $ where [$ opt ]);
491495 if ($ id == 0 && $ idx_where == 2 ) $ wherestr .= ' ' .strtoupper ($ group_prev ).' ' ;
@@ -502,7 +506,7 @@ public static function where($dbcon, $list, $group='and', $idx_where=1, $group_p
502506 public static function group_by ($ dbcon , $ list ) {
503507 $ ret = '' ;
504508 $ group_by = [];
505-
509+
506510 if (is_array ($ list ) && count ($ list ) > 0 ) {
507511 while (list ($ idx , $ group_bylist ) = each ($ list )) {
508512 while (list ($ id , $ fields ) = each ($ group_bylist )) {
@@ -520,11 +524,11 @@ public static function group_by($dbcon, $list) {
520524 else
521525 $ group_by [] = $ fields ;
522526
523- }
527+ }
524528
525529 }
526530 }
527-
531+
528532 $ ret = ' GROUP BY ' .implode (', ' , $ group_by ).' ' ;
529533 }
530534
@@ -549,11 +553,11 @@ public static function join($table, $list) {
549553
550554 if (strpos ($ on2 , '. ' ) === false )
551555 $ on2 = "$ joinlist [1 ]. $ on2 " ;
552-
556+
553557 $ join [] = strtoupper ($ joinlist [0 ])." JOIN $ joinlist [1 ] ON $ on1 = $ on2 " ;
554558 } else
555559 $ join [] = strtoupper ($ joinlist [0 ])." JOIN $ joinlist [1 ] ON $ joinlist [1 ]. $ on1 = $ table. $ on2 " ;
556- } else
560+ } else
557561 $ join [] = strtoupper ($ joinlist [0 ])." JOIN $ joinlist [1 ] ON $ joinlist [1 ]. $ joinlist [2 ] = $ table. $ joinlist [2 ]" ;
558562 }
559563 }
@@ -566,7 +570,7 @@ public static function join($table, $list) {
566570
567571 public static function union ($ list ) {
568572 $ ret = '' ;
569-
573+
570574 if (is_array ($ list ) && count ($ list ) > 0 ) {
571575 $ ret = ' UNION ' .implode (', ' , $ list );
572576 }
@@ -584,15 +588,15 @@ public static function find($dbcon, $table, $filter=array(), $lmt=array(), $odr_
584588 $ union = '' ;
585589
586590 if (is_array ($ filter ) && count ($ filter ) > 0 ) {
587-
591+
588592 while (list ($ syntax , $ query ) = each ($ filter )) {
589593 $ syntax = strtoupper ($ syntax );
590594
591595 switch ($ syntax ) {
592596 case 'SELECT ' :
593597 $ select .= self ::select ($ query );
594598 break ;
595-
599+
596600 case 'WHERE ' :
597601 $ where = self ::where ($ dbcon , $ query );
598602 break ;
@@ -614,7 +618,7 @@ public static function find($dbcon, $table, $filter=array(), $lmt=array(), $odr_
614618 break ;
615619 }
616620 }
617-
621+
618622 }
619623
620624 if (is_array ($ lmt ) && count ($ lmt ) > 0 ) {
0 commit comments