Home > Article > PHP Framework > How to use where and whereor at the same time in tp5
The following tutorial column will introduce to you how to use where and whereor in tp5 at the same time. I hope it will be helpful to friends in need!
Where and whereor in tp5 are used simultaneously
One:$data = db('table')->where(function($query) {
$query->where('key1', value)->whereor('key1',value1);
})->where(['key2'=>value2,'key3'=>value3])->field('key4')->find();
The generated sql statement is:
find key4 FROM `table` WHERE ( `key1` = 'value' OR `key1` = 'value1' ) and `key2` = 'value2' and 'key3' = 'value3';
Two:
$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' )Related recommendations:
The latest 10 thinkphp video tutorials
The above is the detailed content of How to use where and whereor at the same time in tp5. For more information, please follow other related articles on the PHP Chinese website!