Yii2 查询条件
程序员文章站
2022-10-06 12:38:49
Model::find() 字符串格式,例如:'status=1' 哈希格式,例如: ['status' => 1, 'type' => 2] 操作符格式,例如:['like', 'name', 'test'] between like 逻辑条件: ......
model::find()
字符串格式,例如:'status=1'
哈希格式,例如: ['status' => 1, 'type' => 2]
操作符格式,例如:['like', 'name', 'test']
between
//->andfilterwhere(['between','updated_at',$oldtime, $current]) ->andwhere(['between','updated_at',$oldtime, $current])
like
//->andfilterwhere(['like','name',$name]) ->andwhere(['like','name',$name])
逻辑条件:
//第一种
->where(['=', 'status',10])
->andwhere(['like', 'title','yii'])
# where (`status` = 10) and (`title` like '%yii%')
//第二种
->addwhere(['and', 'id=1', 'name=2']);
# where id=1 and name=2
//第三种
->addwhere(['and', 'type=1', ['or', 'id=1', 'id=2']]);
# where type=1 and (id=1 or id=2);
//第四种
->andwhere(['or like','name',['哈哈','苦苦']]);
# where `name` like '%哈哈%' or `name` like '%苦苦%';
//第五种
->addwhere(['or',['like','name','哈哈'],['like','title','苦苦']]);
# where (`status`=1) and ((`name` like '%哈哈%') or (`title` like '%苦苦%'))
上一篇: 数据分析处理库Pandas——索引