下面由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视频教程