我想在一侧添加带有 %
通配符的 like
条件,例如:
where name like 'value%'
我的代码:
Table::find()->filterWhere(['like', 'name' , $_GET['q'].'%' ])
->all();
但是查询结果是:
where name like '%value\%%'
最佳答案
您需要将第四个操作数设置为 false
才能使用自定义 where like 条件:
Table::find()->where(['like', 'name', $_GET['q'] . '%', false]);
来自docs :
Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operand
false
to do so. For example,['like', 'name', '%tester', false]
will generatename LIKE '%tester'
.
关于mysql - Yii2 在一侧添加带有 "%"通配符的 LIKE 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304614/