Thinkphp5 WHERE OR查询用法

in 读书学习 with 0 comment

微信截图_20210901140951.png

1、WHERE OR实现不同字段的相同查询条件,注意看代码

$where['isagent|isvip'] = 1;
$model = DB::('member');

$model->where($where)->select();

$model->where('lid=200 or pid=200')->select();

总结一下,A:$where参数名写法 B:直接用SQL语句

2、WHERE OR字段查询条件,示例

$where['isagent'] = [['eq',1],['eq',2],'or'];

$map['isagent']  = ['eq',1];
$map['username'] = ['like','%山大王%']
$model = DB::('member');

$model->where($where)->select();

$model->whereOr(function ($query) use ($map) {$query->where($map);})->select();

$model->where('isagent=1 or isagent=2')->select();

总结一下,A:普通$where写法 B:闭包写法 C:SQL写法