Symfony2 and Doctrine: how to use findOneBy method taking capitals into account

早过忘川 提交于 2019-12-24 19:59:17

问题


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


来源:https://stackoverflow.com/questions/17458216/symfony2-and-doctrine-how-to-use-findoneby-method-taking-capitals-into-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!