@@ -117,7 +117,7 @@ public function __construct($host = NULL, $username = NULL, $password = NULL, $d
117117 else
118118 $ this ->port = $ port ;
119119
120- if ($ host == null && $ username == null && $ db == null ) {
120+ if ($ username == null && $ db == null ) {
121121 $ this ->isSubQuery = true ;
122122 return ;
123123 }
@@ -427,12 +427,14 @@ public function join($joinTable, $joinCondition, $joinType = '')
427427 {
428428 $ allowedTypes = array ('LEFT ' , 'RIGHT ' , 'OUTER ' , 'INNER ' , 'LEFT OUTER ' , 'RIGHT OUTER ' );
429429 $ joinType = strtoupper (trim ($ joinType ));
430- $ joinTable = filter_var ($ joinTable , FILTER_SANITIZE_STRING );
431430
432431 if ($ joinType && !in_array ($ joinType , $ allowedTypes ))
433432 die ('Wrong JOIN type: ' .$ joinType );
434433
435- $ this ->_join [$ joinType . " JOIN " . self ::$ _prefix . $ joinTable ] = $ joinCondition ;
434+ if (!is_object ($ joinTable ))
435+ $ joinTable = self ::$ _prefix . filter_var ($ joinTable , FILTER_SANITIZE_STRING );
436+
437+ $ this ->_join [] = Array ($ joinType , $ joinTable , $ joinCondition );
436438
437439 return $ this ;
438440 }
@@ -587,7 +589,7 @@ protected function _buildPair ($operator, $value) {
587589 $ subQuery = $ value ->getSubQuery ();
588590 $ this ->_bindParams ($ subQuery ['params ' ]);
589591
590- return " " . $ operator . " ( " . $ subQuery ['query ' ] . ") " ;
592+ return " " . $ operator . " ( " . $ subQuery ['query ' ] . ") " . $ subQuery [ ' alias ' ] ;
591593 }
592594
593595 /**
@@ -679,8 +681,16 @@ protected function _buildJoin () {
679681 if (empty ($ this ->_join ))
680682 return ;
681683
682- foreach ($ this ->_join as $ prop => $ value )
683- $ this ->_query .= " " . $ prop . " on " . $ value ;
684+ foreach ($ this ->_join as $ data ) {
685+ list ($ joinType , $ joinTable , $ joinCondition ) = $ data ;
686+
687+ if (is_object ($ joinTable ))
688+ $ joinStr = $ this ->_buildPair ("" , $ joinTable );
689+ else
690+ $ joinStr = $ joinTable ;
691+
692+ $ this ->_query .= " " . $ joinType . " JOIN " . $ joinStr ." on " . $ joinCondition ;
693+ }
684694 }
685695
686696 /**
@@ -946,7 +956,8 @@ public function getSubQuery () {
946956
947957 array_shift ($ this ->_bindParams );
948958 $ val = Array ('query ' => $ this ->_query ,
949- 'params ' => $ this ->_bindParams
959+ 'params ' => $ this ->_bindParams ,
960+ 'alias ' => $ this ->host
950961 );
951962 $ this ->reset ();
952963 return $ val ;
@@ -1031,9 +1042,9 @@ public function func ($expr, $bindParams = null) {
10311042 /**
10321043 * Method creates new mysqlidb object for a subquery generation
10331044 */
1034- public static function subQuery ()
1045+ public static function subQuery ($ subQueryAlias = "" )
10351046 {
1036- return new MysqliDb ( );
1047+ return new MysqliDb ( $ subQueryAlias );
10371048 }
10381049
10391050 /**
0 commit comments