下面由thinkphp教學專欄為大家介紹tp5中的where與whereor怎麼同時使用,希望對需要的朋友有幫助!
tp5中的where與whereor同時使用
一:
$data = db('table')->where(function($query) { $query->where('key1', value)->whereor('key1',value1); })->where(['key2'=>value2,'key3'=>value3])->field('key4')->find();
產生的sql語句為:
find key4 FROM `table` WHERE ( `key1` = 'value' OR `key1` = 'value1' ) and `key2` = 'value2' and 'key3' = 'value3';
二:
$data = db('table')->where(function($query) { $query->where('key1', value)->whereor('key1',value1); })->whereor(function($query){ $query->where(['key2'=>value2]->whereor(['key3'=>value3])) })->field('key4')->find(); find 'key4' FROM `table` WHERE ( `key1` = value OR `key1` = value1 ) OR ( `key2` = 'value2' OR `key3` = 'value3' )
#相關推薦:最新的10個thinkphp影片教學
以上是tp5中的where與whereor怎麼同時使用的詳細內容。更多資訊請關注PHP中文網其他相關文章!