When using LIKE with % in MySQL PDO, row with a capital not returned

mysql, pdo, php

Solution

This depends on the collation of the field.

If the collation ends _cs then it's case sensitive, if it ends _ci then case insensitive.

Change the properties of the field and the indexes / search will follow.

Problem

Okay so say I am doing a search for "PersonName" and I type in "person" it doesn't find the person but "Person" does, is there a way to tell it to look for anything resembling my input? I am doing the search simply like this: ``` $db->sqlquery(" SELECT `user_id` FROM `users` WHERE `username`LIKE ?", array("%$user%")); ```

Original source