We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Case insensitive findBy*?

Hi all,

Is there a way to allow the findBy* to be case insensitive? For example, if I have Users::findByEmail('[email protected]') it'll find a result but Users::findByEmail('[email protected]') won't find a result.

Is there some kind of setting, or filtering, or something that can be applied as and when required to be case insensitive, or would it just be easier to re-write the find line to use PHQL to do it more manually?

Cheers,

Andy



93.7k
Accepted
answer
edited Apr '18

Thats depending on your table collation.

SHOW TABLE STATUS LIKE 'YOUR_TABLE_NAME'

It's utf8mb4_bin which I'm assuming is forcing it to be a case sensitive search on the MySQL side? :-/

If that's the case then it looks like a little rewrite is in order for my code. :-D



43.9k

Hi,

It's utf8mb4_bin which I'm assuming is forcing it to be a case sensitive search on the MySQL side? :-/

yes so far I understand: https://stackoverflow.com/questions/3936967/mysql-case-insensitive-select

Just to follow up on this in case anyone else is interested; yes, it was definitely the utf8mb4_bin collation that was the issue for me. For the fields where I wanted to ensure a case insensitive search I changed that to utf8mb4_general_ci - even though the table itself remained with the *_bin collation. This allowed me to have case insensitive where I didn't care, case sensitive where I did (like generated codes I wanted to match exactly), and not have to change any code.