Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,16 +88,16 @@ create('profile',
---

innerJoin(string $leftTable = null, string $rightTable = null,
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

leftJoin(string $leftTable = null, string $rightTable = null,
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

rightJoin(string $leftTable = null, string $rightTable = null,
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);

fullJoin(string $leftTable = null, string $rightTable = null,
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
string $leftColumn = null, string $rightColumn = null, string $tableAs = null, $condition = EQ);
---

```php
Expand DownExpand Up@@ -179,7 +179,7 @@ foreach ($result as $row){
$result = $db->selecting('profile', 'name, email',
// Conditionals can also be called, stacked with other functions like:
// innerJoin(), leftJoin(), rightJoin(), fullJoin()
// as (leftTable, rightTable, leftColumn, rightColumn, equal condition),
// as (leftTable, rightTable, leftColumn, rightColumn, tableAs, equal condition),
// where( eq( columns, values, _AND ), like( columns, _d ) ),
// groupBy( columns ),
// having( between( columns, values1, values2 ) ),
Expand Down
20 changes: 12 additions & 8 deletions lib/ezFunctions.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -370,11 +370,12 @@ function innerJoin(
$rightTable = '',
$leftColumn = null,
$rightColumn = null,
$tableAs = null,
$condition = \EQ
){
$ezQuery = \getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->innerJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $condition)
return ($ezQuery instanceOf DatabaseInterface)
? $ezQuery->innerJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition)
: false;
}

Expand All@@ -383,11 +384,12 @@ function leftJoin(
$rightTable = '',
$leftColumn = null,
$rightColumn = null,
$tableAs = null,
$condition = \EQ
){
$ezQuery = \getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->leftJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $condition)
return ($ezQuery instanceOf DatabaseInterface)
? $ezQuery->leftJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition)
: false;
}

Expand All@@ -396,11 +398,12 @@ function rightJoin(
$rightTable = '',
$leftColumn = null,
$rightColumn = null,
$tableAs = null,
$condition = \EQ
){
$ezQuery = \getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->rightJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $condition)
return ($ezQuery instanceOf DatabaseInterface)
? $ezQuery->rightJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition)
: false;
}

Expand All@@ -409,11 +412,12 @@ function fullJoin(
$rightTable = '',
$leftColumn = null,
$rightColumn = null,
$tableAs = null,
$condition = \EQ
){
$ezQuery = \getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->fullJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $condition)
return ($ezQuery instanceOf DatabaseInterface)
? $ezQuery->fullJoin($leftTable, $rightTable, $leftColumn, $rightColumn, $tableAs, $condition)
: false;
}

Expand Down
28 changes: 21 additions & 7 deletions lib/ezQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,6 +186,7 @@ public function innerJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
){
return $this->joining(
Expand All@@ -194,6 +195,7 @@ public function innerJoin(
$rightTable,
$leftColumn,
$rightColumn,
$tableAs,
$condition
);
}
Expand All@@ -203,6 +205,7 @@ public function leftJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
){
return $this->joining(
Expand All@@ -211,6 +214,7 @@ public function leftJoin(
$rightTable,
$leftColumn,
$rightColumn,
$tableAs,
$condition
);
}
Expand All@@ -220,6 +224,7 @@ public function rightJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
){
return $this->joining(
Expand All@@ -228,6 +233,7 @@ public function rightJoin(
$rightTable,
$leftColumn,
$rightColumn,
$tableAs,
$condition
);
}
Expand All@@ -237,14 +243,16 @@ public function fullJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
){
return $this->joining(
'FULL',
$leftTable,
$rightTable,
$$leftColumn,
$leftColumn,
$rightColumn,
$tableAs,
$condition
);
}
Expand All@@ -269,36 +277,42 @@ public function fullJoin(
*
* @param string $leftColumn -
* @param string $rightColumn -
* @param string $tableAs -
*
* @param string $condition -
*
* @return bool|string JOIN sql statement, false for error
*/
*/
private function joining(
String $type = \_INNER,
string $leftTable = null,
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
){
if (
!\in_array($type, \_JOINERS)
|| !\in_array($condition, \_BOOLEAN)
|| empty($leftTable)
|| empty($rightTable) || empty($columnFields) || empty($leftColumn)
|| empty($rightTable)
|| empty($leftColumn)
){
return false;
}

if (empty($tableAs))
$tableAs = $rightTable;

if (\is_string($leftColumn) && empty($rightColumn))
$onCondition = ' ON ' . $leftTable . $leftColumn . ' = ' . $rightTable . $leftColumn;
$onCondition = ' ON ' . $leftTable . '.' . $leftColumn . ' = ' . $tableAs . '.' . $leftColumn;
elseif ($condition !== \EQ)
$onCondition = ' ON ' . $leftTable . $leftColumn . " $condition " . $rightTable . $rightColumn;
$onCondition = ' ON ' . $leftTable . '.' . $leftColumn . ' ' . $condition . ' ' . $tableAs . '.' . $rightColumn;
else
$onCondition = ' ON ' . $leftTable . $leftColumn . ' = ' . $rightTable . $rightColumn;
$onCondition = ' ON ' . $leftTable . '.' . $leftColumn . ' = ' . $tableAs . '.' . $rightColumn;

return ' ' . $type . ' JOIN ' . $rightTable . $onCondition;
return ' ' . $type . ' JOIN ' . $rightTable . ' AS ' . $tableAs . ' ' . $onCondition;
}

public function orderBy($orderBy, $order)
Expand Down
8 changes: 8 additions & 0 deletions lib/ezQueryInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -107,6 +107,7 @@ public function having(...$having);
* @param string $rightTable -
* @param string $leftColumn -
* @param string $rightColumn -
* @param string $tableAs -
* @param string $condition -
*
* @return bool|string JOIN sql statement, false for error
Expand All@@ -116,6 +117,7 @@ public function innerJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
);

Expand All@@ -139,6 +141,7 @@ public function innerJoin(
* @param string $rightTable -
* @param string $leftColumn -
* @param string $rightColumn -
* @param string $tableAs -
* @param string $condition -
*
* @return bool|string JOIN sql statement, false for error
Expand All@@ -148,6 +151,7 @@ public function leftJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
);

Expand All@@ -171,6 +175,7 @@ public function leftJoin(
* @param string $rightTable -
* @param string $leftColumn -
* @param string $rightColumn -
* @param string $tableAs -
* @param string $condition -
*
* @return bool|string JOIN sql statement, false for error
Expand All@@ -180,6 +185,7 @@ public function rightJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
);

Expand All@@ -202,6 +208,7 @@ public function rightJoin(
* @param string $rightTable -
* @param string $leftColumn -
* @param string $rightColumn -
* @param string $tableAs -
* @param string $condition -
*
* @return bool|string JOIN sql statement, false for error
Expand All@@ -211,6 +218,7 @@ public function fullJoin(
string $rightTable = null,
string $leftColumn = null,
string $rightColumn = null,
string $tableAs = null,
$condition = \EQ
);

Expand Down
Loading