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

It could also be a problem with your table COLLATE setting

This CREATE statement will force your select queries to be case sensitive even when using LIKE operators:

CREATE
  table instituts (inst_name VARCHAR(64))
  CHARACTER SET latin1 COLLATE latin1_general_cs;

Whereas this one will ensure case-insensitivity:

CREATE
  table instituts (inst_name VARCHAR(64))
  CHARACTER SET latin1

Try using LIKE instead of =:

$req="SELECT * FROM INSTITUTS WHERE `inst_name` LIKE '$fc_inst'";

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.

Tags:

Mysql

Php