我正在使用一个使用德语名称的数据库,即 Fürst
。现在我构建了一个带有搜索字段的 HTML 表单。使用 htmlentities
和一些测试来验证没有输入“坏东西”,然后在查询之前输入 html_entity_decode
。一个简单的查询将如下所示:
SELECT * FROM user_table WHERE firstname LIKE "%fü%" OR lastname LIKE "%fü%"
但是,这不仅可以找到 Fürst
,还可以找到 Furt
。我怎样才能解决这个问题?数据库和表格位于 utf8_unicode_ci
中,并且必须保持原样。
最佳答案
这是 collations for each charset
SELECT * FROM user_table WHERE firstname LIKE "%fü%" COLLATE utf8mb4_german2_ci
OR lastname LIKE "%fü%" COLLATE utf8mb4_german2_ci
utf8mb4_unicode_ci 可能也可以。
关于mysql - 使用 LIKE 条件用 sql 搜索德语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35769718/