所属分类:php教程
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怎么同时使用的详细内容,更多请关注zzsucai网其它相关文章!