+ 1
How to make a LIKE clause with a param in MYSQL?
I want to filter some content LIKE some user input stored into a param. I’m addition, I want that query to ignore both case and accent. Could give me any ideas?
1 ответ
+ 3
You can turn both the column content as well as the user input to the same case (like both upper) to make the query case-insensitive.
To search for the input anywhere in the field text, enclose the content in % signs:
WHERE UPPER(col) LIKE '%INPUT%'
To ignore accents, check how to add COLLATE clause with appropriate character set.
https://dev.mysql.com/doc/refman/8.0/en/charset-collate.html
Another piece of advice: sanitize your input (remove special characters) to avoid the possibility of SQL injection attacks, and use prepared statement (or equivalent in your programming language) to assemble the SQL query, rather than just combining strings.