yii2 中区分大小写的查询
Case sensitive query in yii2
为了在 yii2 中查找记录,我使用以下代码:
$response = Response::findOne(['unique_url' => $unique_url]);
但它 return 记录不考虑 $unique_url
大小写。
如何区分大小写?
我认为你应该使用 LIKE BINARY
为此,您应该扩展模型搜索,在查询条件中添加子句
public function search($params)
{
$query = YuorModel::find();
.......
.......
$query->andFilterWhere(['like binary', 'unique_url', $this->unique_url])
->andFilterWhere(['like', 'your_field2', $this->your_field2])
.......
我为此找到的最佳解决方案:
Response::find()->where('BINARY [[unique_url]]=:unique_url', ['unique_url'=>$unique_url])->one();
为了在 yii2 中查找记录,我使用以下代码:
$response = Response::findOne(['unique_url' => $unique_url]);
但它 return 记录不考虑 $unique_url
大小写。
如何区分大小写?
我认为你应该使用 LIKE BINARY
为此,您应该扩展模型搜索,在查询条件中添加子句
public function search($params)
{
$query = YuorModel::find();
.......
.......
$query->andFilterWhere(['like binary', 'unique_url', $this->unique_url])
->andFilterWhere(['like', 'your_field2', $this->your_field2])
.......
我为此找到的最佳解决方案:
Response::find()->where('BINARY [[unique_url]]=:unique_url', ['unique_url'=>$unique_url])->one();