I needed to create a query that did a case insensitive search using the LIKE command in MySQL and I quickly realised that in order to do this I would need to alter both the parameter and the table data to be the same case. This can be done by using the MySQL UPPER() command on the table data and the strtoupper() PHP function on the input data.
- $name = strtoupper('phil');
- $query = "SELECT * FROM users WHERE UPPER(forename) LIKE '" . $name . "%'";
This will produce the following SQL query.
- SELECT * FROM users WHERE UPPER(forename) LIKE 'P%'
I hope that little tip comes in handy to someone looking for the same solution.