Search code examples
activerecordyii2case-sensitive

Case sensitive query in yii2


To find record in yii2 I use following code:

$response = Response::findOne(['unique_url' => $unique_url]);

But it return record regardless $unique_url case. How to do it case sensitive?


Solution

  • I think you should use LIKE BINARY

    and for this you should extended you modelSearch adding the clause in query condition

    public function search($params)
    {
        $query = YuorModel::find();      
        .......
        .......
    
        $query->andFilterWhere(['like binary', 'unique_url', $this->unique_url])
              ->andFilterWhere(['like', 'your_field2', $this->your_field2])
        .......