有一个非常简单的野外搜索:
"SELECT firstname, lastname, email, text FROM members WHERE firstname LIKE '%$word%' OR lastname LIKE '%$word%' OR email LIKE '%$word%' OR text LIKE '%$word%'"
如果我搜索“test”,它会找到“test”而不是“Test”,我该如何修复? 奇怪的是,在另一个数据库中,它找到了“测试”和“测试”这两个词,它们正在运行“latin1_swedish_ci”。
我认为“COLLATE”声明会有所帮助,但我无法让它工作:(
答案 0 :(得分:0)
"SELECT firstname, lastname, email, text FROM members WHERE UPPER(firstname) LIKE UPPER('%$word%') OR UPPER(lastname) LIKE UPPER('%$word%') OR UPPER(email) LIKE UPPER('%$word%') OR UPPER(text) LIKE UPPER('%$word%')"
尝试这样做,将每个文本转换为大写后搜索
答案 1 :(得分:0)
"SELECT firstname, lastname, email, text
FROM members
WHERE upper(firstname) LIKE upper('%$word%')
OR upper(lastname) LIKE upper('%$word%')
OR upper(email) LIKE upper('%$word%')
OR upper(text) LIKE upper('%$word%')"
"SELECT firstname, lastname, email, text
FROM members
WHERE lower(firstname) LIKE lower('%$word%')
OR lower(lastname) LIKE lower('%$word%')
OR lower(email) LIKE lower('%$word%')
OR lower(text) LIKE lower('%$word%')"
这应该有效:)