Symfony2 and Doctrine: how to use findOneBy method

2019-09-09 10:47发布

问题:

Using Symfony2, Doctrine and MySQL, I am using findOneBy method.

I need it to take capitals into account when talking about string criteria fields.

Example: imagine I have this path field in some table in my database.

id  path
---------
1   path1
2   path2
3   path3
4   path4

If I do findOneByPath("PATH2") it will find the second row.

The question: how can I make it to distinguish capitals, so that it wouldn't find any row in the described case?

回答1:

The issue is not a doctrine/symfony issue - the problem is that your table collation is case-insensitive (this is the default), if you want searches to be case sensitive you need to use a different collation on your tables.

  • Doctrine and collation
  • MySQL Docs for case sensitivity
  • MySQL Docs for altering collaction