Yii2 where使用
Yii2 where使用
Yii2 查询运算符
// 运算符有 // and、or、not、 // between、not between、 // in、not in、 // like、or like、not like、or not like、 // exists、not exists、 // >、<、=、>=、<=、!=
1) and 查询
// and 查询 // SELECT * FROM `user` WHERE id=1 and status=10 $model = User::find()->where('id=:id and status=:status', [ ':id' => 1, ':status' => 10 ])->all();
2) or 查询
// or 查询 // SELECT * FROM `user` WHERE id=1 or status=9 $model = User::find()->where('id=:id or status=:status', [ ':id' => 1, ':status' => 9 ])->all();
3) and or 查询
// and or 查询 // SELECT * FROM `user` WHERE status=10 and (id=1 or id=2) $model = User::find()->where('status=:status and (id=:id or id=:sid)', [ ':status' => 10, ':id' => 1, ':sid' => 2 ])->all(); // and or 查询 // SELECT * FROM `user` WHERE (status=10) AND ((id=1) OR (id=2)) $model = User::find()->where(['and','status=10',['or','id=1','id=2']])->all();
4) like 查询
// like 查询 // SELECT * FROM `user` WHERE `username` LIKE '%张%' $model = User::find()->where(['like', 'username', "张"])->all();
5) or like 查询
// or like 查询 // SELECT * FROM `user` WHERE `ssusername` LIKE '%张%' OR `username` LIKE '%李%' $model = User::find()->where(['or like', 'username', ['张','李']])->all();