Thinkphp 邏輯與,邏輯或的複合查詢

查詢數據庫時,有時會遇到即使用了“邏輯與”也是用了“邏輯或”的查詢條件。
他的SQL語句如下:

SELECT * FROM Persons WHERE (FirstName='Thomas' OR FirstName='William')
AND LastName='Carter'
//查詢名字爲"Thomas""William",並且姓氏爲"Carter"的人

在Thinkphp 中,實現這樣的查詢的方法如下

$personModel = D('person');
$where['firstName'] = array('eq','Thomas');
$where['firstName'] array('eq','William');
$where['_logic'] = "or";
$whereAll['_complex'] = $where;
$whereAll['lastname'] = "Carter";

$persons = $personModel->where($whereAll)->select();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章