Query_Builder_Where クラスは、クエリ構築における条件及び制限を設定するロジックを扱います。
すべての種類の where ステートメント (BETWEEN や IN などを含む) はここで扱います。このクラスは、抽象クラスのためインスタンスは生成できず、同じ機能を共有する他のクラスに継承されます。
それらのクラスは次のとおりです。:
注意: Query_Builder_Where は上記のクラスから継承されるため、"current instance" はそれらの一つが返却されます。
where メソッドはand_whereのエイリアスです。
and_where メソッドは、WHERE ステートメントを追加します。
静的 |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$column |
mixed |
必須 |
Column name or array($column, $alias), object, or callback |
$op |
string |
null
|
Logic operator: =, !=, IN, BETWEEN and LIKE. If none is provided this will fallback to '=' |
$value |
string |
null
|
カラムの値 |
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('name', '!=', 'John');
$query->and_where('surname', 'Doe');
$query->where(function($query){
$query->where('email', 'jim@jim.com')
->or_where('email', 'haha@joke.com');
});
|
or_where メソッドは OR WHERE ステートメントを追加します。
静的 |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$column |
string |
必須 |
Column name or array($column, $alias), object or callback |
$op |
string |
null
|
Logic operator: =, !=, IN, BETWEEN. If none is provided this will fallback to '=' |
$value |
string |
null
|
カラムの値 |
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('name', '=', 'John');
$query->or_where('surname', 'Doe');
$query->or_where(function($query){
$query->where('email', 'jim@jim.com')
->and_where('id', 4);
});
|
where_open メソッドは、and_where_openのエイリアスです。
and_where_open メソッドは、 SQL クロージャ を開き、それを AND で追加します。
静的 |
No |
パラメータ |
None
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('name', 'john');
$query->and_where_open();
|
or_where_open メソッドは SQL クロージャを開き、それを OR で追加します。
静的 |
No |
パラメータ |
None
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('name', 'john');
$query->or_where_open();
|
where_close メソッドは and_where_closeのエイリアスです。
and_where_close メソッドは、SQL クロージャを閉じます。
静的 |
No |
パラメータ |
None
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('email', 'like', '%@example.com');
$query->and_where_open();
$query->where('name', 'John');
$query->or_where('surname', 'Doe');
$query->and_where_close();
|
or_where_close メソッドは、SQL クロージャを閉じます。
静的 |
No |
パラメータ |
None
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->where('email', 'like', '%@example.com');
$query->or_where_open();
$query->where('name', 'John');
$query->and_where('surname', 'Doe');
$query->or_where_close();
|
order_by メソッドは、結果/実行の順序をセットします。
静的 |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$column |
string |
必須 |
カラム名 |
$direction |
string |
null |
'asc' もしくは 'desc'が指定可能です。 |
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->order_by('name');
$query->order_by('email', 'asc');
$query->order_by('surname', 'desc');
|
limit メソッドは、 取得/更新する、レコード数の上限をセットします。
静的 |
No |
パラメータ |
パラメータ |
型 |
規定値 |
説明 |
$number |
int |
必須 |
The number of rows |
|
返り値 |
Returns the current instance. |
例 |
$query = DB::select('*')->from('users');
$query->limit(10);
|