1

进行非常简单的通配符搜索:

"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”,我该如何解决这个问题?奇怪的是,在另一个数据库中,它找到了“Test”和“test”这两个词,它们正在运行“latin1_swedish_ci”。

我认为“整理”语句会有所帮助,但我无法让它工作:(

4

2 回答 2

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%')"

尝试这样做它会在将每个文本转换为大写后进行搜索

于 2013-02-16T12:20:01.207 回答
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%')"

这应该工作:)

于 2013-02-17T17:59:29.557 回答