课程推荐:Laravel框架项目实战全程实录#PHP项目的主流开发模式--学习猿地免费体验课
在数据查询时候,多条件查询,使用场景
//单个值
$data_where[‘id‘] = 1
// in 条件 写法一
$ids = [1,2,3,4,5];
$data_where[] = [DB::raw("字段名 in ({$ids})"),‘1‘];
//in条件写法二
$data_where[] = [‘in‘=>[‘id‘=>$ids]];
$condition[] =[‘id‘,‘in‘,$ids]; // 这是错误的写法
// Illuminate\Database\Query\Builder关于operators定义中,并没有in
public $operators = [
‘=‘, ‘<‘, ‘>‘, ‘<=‘, ‘>=‘, ‘<>‘, ‘!=‘,
‘like‘, ‘like binary‘, ‘not like‘, ‘between‘, ‘ilike‘,
‘&‘, ‘|‘, ‘^‘, ‘<<‘, ‘>>‘,
‘rlike‘, ‘regexp‘, ‘not regexp‘,
‘~‘, ‘~‘, ‘!~‘, ‘!~‘, ‘similar to‘,
‘not similar to‘, ‘not ilike‘, ‘*‘, ‘!*‘,
];
【Laravel】DB查询 where 例子记录
标签:like 记录 cond query amp 字段 pre mil build
© 著作权归作者所有
发表评论