##擴展查詢條件
如果使用where、andWhere、orWhere方法依然不能滿足需要,可使用擴展查詢條件方法。
~~~
DbModel::appendWhere($append, $appendBindings = [])
~~~
參數表:
| 參數名稱 | 必選 | 類型 | 說明 |
| --- | --- | --- | --- |
| append | 是 | string | 查詢條件子句 |
| appendBindings | 否 | array | 查詢條件參數綁定的數據 |
append中的參數值推薦使用參數化查詢進行綁定。在append中,使用“?”占位符表示要綁定的參數,在appendBindings數組中一一對應的傳入要綁定的值。
該方法最大化的讓查詢條件靈活化,可以滿足各種奇葩的查詢條件。
用例:
~~~
/**
* 測試擴展查詢條件
*
* @return int
*/
public function testAppendWhere()
{
$count = $this->where('name', '楊文杰')
->appendWhere('and id <= ?', [15])
->getCount();
return $count;
}
~~~