is it possible to make a search with Doctrine case insensitive?
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 .
MySQL's like should be case-insensitive by default.
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.
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.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With