How to make a SELECT in PHP/MySQL case insensitive?

前端 未结 7 832
面向向阳花
面向向阳花 2020-12-06 11:55

Her\'s my probleme, i guess its really basic.

I\'m trying to lookup in the database if a line does exist. heres my code :

$req=\"SELECT * FROM INSTIT         


        
相关标签:
7条回答
  • 2020-12-06 12:49

    you can use LIKE:

    WHERE foo LIKE 'bar'
    

    Or you can cast both lowercase with:

    WHERE LOWER(foo) = LOWER("bar")
    

    The example with LOWER() is most effective where you know that all of your data in the database is already lower cased and then you can just execute:

    WHERE foo = LOWER("bar")
    

    This would be a cheaper comparison than the LIKE if you can lower case all of the data in your database.

    0 讨论(0)
提交回复
热议问题