tp5中的where与whereor同时使用

1.

$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';

 

2

$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' )

 

你可能感兴趣的:(mysql)