M
M
Maxim Osadchy2017-09-03 15:19:04
MySQL
Maxim Osadchy, 2017-09-03 15:19:04

How to make case insensitive search in yii2?

The database contains a product code, for example CODE1, if you write in caps - it will find it, code1 does not find it.
action snippet:

$q = trim(Yii::$app->request->get('q'));
$query = Product::find()->where(['like', 'name', $q])->orWhere(['like binary', 'id', $q]);

Maybe the solution to this problem lies not in yii, but in mysql itself, but I am also not strong in it, so I ask you to tell me how to do this.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Pavlenko, 2017-09-03
@waspmax1

like binary just indicates that the search is case-sensitive.
In general, the search there is just case insensitive if the encoding is utf8_general_ci (ci - just means case insensitive)

M
melnikov_m, 2017-09-03
@melnikov_m

php.net/mb_strtolower
php.net/manual/ru/function.mb-strtoupper.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question