Home > PHP Framework > YII > The difference between andWhere and andFilterWhere in yii2

The difference between andWhere and andFilterWhere in yii2

angryTom
Release: 2019-11-26 17:17:24
forward
4015 people have browsed it

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`
Copy after login

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!

Related labels:
yii
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template