I created an online store and I noticed a problem with the search function. If the user enters a search string, I doSELECT * FROM PRODUCTS WHERE DESCRIPTION LIKE %....%
This works well, but problems exist in special charachters. Imagine I have products like préparé or côte à l'os. When the user searches “prepare” or “pave l'os”, the products will not be found, however they are there.
The problem is also different. If a user searches for "dûroc", but my product is in the database as "duroc", he will not find it.
It could also be something in between: users are looking for “cook” or “côte a l'os”.
How can I fix this problem or at least reduce it?
MySQL 5.1.73 / PHP 5.6
UPDATE
I read some additional tests after reading these answers and I can give further details. If I use tools like MySQL Workbench or Sequel Pro, everything works fine. Therefore, I can execute SELECT * FROM PRODUCTS WHERE DESCRIPTION LIKE '%prepare%'or SELECT * FROM PRODUCTS WHERE DESCRIPTION LIKE '%preparé%'; they both return every entry where the description contains “prepare”, “préparé” or “prepare”, just like I want. I did not know that MySQL did this because SQL Server did not test it.
Then return to the site. If users type “prepare,” all the same, everything is going well, all records are returned, as indicated above. But then, if users type “drug”, it does not return anything, even those who have “drug” in the description.
This is the request in PHP that I am using:
$qryPLU = sprintf(SELECT * FROM PRODUCTS WHERE DESCRIPTION LIKE "%%%s%%", $conn->real_escape_string($mywgid));
, :
SELECT * FROM PRODUCTS WHERE DESCRIPTION LIKE '%PREPARé%'
- , é , , , , .
- @Reversal , .