YII2 查询
1.OR 查询
// 我们要查询id等于1或者id等于3的数据$userInfo = User::find()->where(['or' , 'id = 1' , 'id = 3'])->all();// 我们同样可以使用以下方式$userInfo = User::find()->where(['or' , ['=' , 'id' , 1] , ['=' , 'id' , 3]])->all();// 假如我们要查询id在4,8,9范围内 或者 id在1,2,3范围内呢?$userInfo = User::find()->where(['or' , ['id' => [4,8,9]] , ['id' => [1,2,3]]])->all();// like查询 根据条件$posts模糊查询$userInfo = User::find()->where(['or' , ['LIKE','name',$posts],['LIKE','mobile',$posts])->all();// like查询 单边加%
$userInfo = User::find()->where(['or' , ['LIKE','name',$posts.'%',false],['LIKE','mobile',$posts.'%',false])->all();2.打印SQL语句
$query = Modle::find();
$query-> .........// 执行的 操作
$sql = $query->createCommand()->getRawSql();
var_dump($sql);

浙公网安备 33010602011771号