Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 839
Dmitry Borovkov Avatar asked Dec 25 '15 19:12

Dmitry Borovkov


2 Answers

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])
    .......
like image 117
ScaisEdge Avatar answered Nov 15 '22 19:11

ScaisEdge


Best solution which I found for this:

Response::find()->where('BINARY [[unique_url]]=:unique_url', ['unique_url'=>$unique_url])->one();
like image 44
Dmitry Borovkov Avatar answered Nov 15 '22 17:11

Dmitry Borovkov