add left and right join to ModelMysql.
This commit is contained in:
parent
9539b43212
commit
f5967591e1
@ -18,6 +18,9 @@ class ModelMySQL {
|
||||
static protected $querySelect = [
|
||||
'select' => '*',
|
||||
'where' => '',
|
||||
'leftJoin' => '',
|
||||
'rightJoin' => '',
|
||||
'on' => '',
|
||||
'AndOr' => '',
|
||||
'orderBy'=>'',
|
||||
'groupBy'=>'',
|
||||
@ -49,6 +52,9 @@ class ModelMySQL {
|
||||
self::$querySelect = [
|
||||
'select' => '*',
|
||||
'where' => '',
|
||||
'leftJoin' => '',
|
||||
'rightJoin' => '',
|
||||
'on' => '',
|
||||
'AndOr' => '',
|
||||
'orderBy'=>'',
|
||||
'groupBy'=>'',
|
||||
@ -59,6 +65,14 @@ class ModelMySQL {
|
||||
private static function buildQuery(){
|
||||
$sql = 'SELECT '.self::$querySelect['select'].' FROM '.self::table();
|
||||
|
||||
if (self::$querySelect['leftJoin'] != ''){
|
||||
$sql .= ' LEFT JOIN ' . self::$querySelect['leftJoin'];
|
||||
$sql .= ' ON '. self::$querySelect['on'];
|
||||
} elseif(self::$querySelect['rightJoin'] != ''){
|
||||
$sql .= ' RIGHT JOIN ' . self::$querySelect['leftJoin'];
|
||||
$sql .= ' ON '. self::$querySelect['on'];
|
||||
}
|
||||
|
||||
if (self::$querySelect['where'] != ''){
|
||||
$sql .= ' WHERE '.self::$querySelect['where'];
|
||||
|
||||
@ -228,6 +242,37 @@ class ModelMySQL {
|
||||
return new static();
|
||||
}
|
||||
|
||||
public static function leftJoin($table, $columnA, $operator, $columnB = null){
|
||||
if (is_null($columnB)){
|
||||
$columnB = $operator;
|
||||
$operator = '=';
|
||||
}
|
||||
|
||||
$columnA = self::db()->real_escape_string($columnA);
|
||||
$columnB = self::db()->real_escape_string($columnB);
|
||||
|
||||
self::$querySelect['leftJoin'] = $table;
|
||||
self::$querySelect['on'] = "$columnA$operator$columnB";
|
||||
|
||||
|
||||
return new static();
|
||||
}
|
||||
|
||||
public static function rightJoin($table, $columnA, $operator, $columnB = null){
|
||||
if (is_null($columnB)){
|
||||
$columnB = $operator;
|
||||
$operator = '=';
|
||||
}
|
||||
|
||||
$columnA = self::db()->real_escape_string($columnA);
|
||||
$columnB = self::db()->real_escape_string($columnB);
|
||||
|
||||
self::$querySelect['rightJoin'] = $table;
|
||||
self::$querySelect['on'] = "$columnA$operator$columnB";
|
||||
|
||||
|
||||
return new static();
|
||||
}
|
||||
|
||||
public static function and($column, $operator, $value=null){
|
||||
if (is_null($value)){
|
||||
|
Loading…
Reference in New Issue
Block a user