Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine LIKE case insensitive

Tags:

is it possible to make a search with Doctrine case insensitive?

like image 259
chchrist Avatar asked Nov 08 '10 20:11

chchrist


People also ask

Is like case-sensitive?

LIKE performs case-insensitive substring matches if the collation for the expression and pattern is case-insensitive. For case-sensitive matches, declare either argument to use a binary collation using COLLATE , or coerce either of them to a BINARY string using CAST .

Is like case-insensitive MySQL?

MySQL's like should be case-insensitive by default.

What is case-insensitive search?

By default, searches are case-insensitive. You can make your search case-sensitive by using the case filter. For example, the following search returns only results that match the term HelloWorld . It excludes results where the case doesn't match, such as helloWorld or helloworld . case:yes HelloWorld.

How do I select case-sensitive in MySQL?

It is important to note that MySql is not only case insensitive for columns using an _ci collation (which is typically the default), but also accent insensitive. This means that 'é' = 'e' . Using a binary collation (or the binary operator) will make string comparisons accent sensitive as well as case sensitive.


2 Answers

This depends mainly on your Database-Server. A LIKE with MySQL is case insensitive a like with PostgreSQL is case sensitive. But you can help yourself with something like this:

$pattern = strtolower('HEllO WorlD'); $q = Doctrine_Query::create()        ->select('u.username')        ->from('User u')        ->where("LOWER(u.username) LIKE ?", $pattern); 
like image 85
Timo Haberkern Avatar answered Sep 27 '22 20:09

Timo Haberkern


Also, you can try:

$queryBuilder->where('LOWER(b.title) LIKE LOWER(:query)')         ->setParameter('query', '%' . $query . '%'); 

Important: After converting a string that contains special characters to lower case with strtolower(), the special characters don’t appear correct.

like image 33
Osoian Marcel Avatar answered Sep 27 '22 19:09

Osoian Marcel