Home >PHP Framework >YII >The difference between andWhere and andFilterWhere in yii2
The difference between andWhere and andFilterWhere in yii2
In yii2, many conditions are often used to combine and judge the query data, so you must understand andWhere Differences from andFilterWhere for flexible use.
#andWhere() //定义一个不为空的参数 $name = 'lisi'; $query = Model::find(); $query->andWhere(['name'=>$name]); //生成的语句 SELECT * FROM `table_name` WHERE `name`='lisi' //定义一个为空的参数 $name = ''; $query->andWhere(['name'=>$name]); //生成的语句 SELECT * FROM `table_name` WHERE `name`='' #andFilterWhere //定义一个不为空的参数 $name = 'lisi'; $query = Model::find(); $query->andFilterWhere(['name'=>$name]); //生成的语句 SELECT * FROM `table_name` WHERE `name`='lisi' //定义一个为空的参数 $name = ''; $query->andFilterWhere(['name'=>$name]); //生成的语句 SELECT * FROM `table_name`
You should be able to see the difference by looking at the code. When using andWhere, the condition will be added regardless of whether the query condition parameter is empty or not. andFilterWhere, when the condition parameter is empty, the condition will be automatically filtered.
Recommended: "YII Tutorial"
The above is the detailed content of The difference between andWhere and andFilterWhere in yii2. For more information, please follow other related articles on the PHP Chinese website!