sql查询中match against时,如果字符串有@符号报错

在使用 MySQL 的 MATCH ... AGAINST ...进行全文搜索时,如果搜索字符串中包含 @符号,确实可能会引发错误。这是因为在全文索引的布尔模式(BOOLEAN MODE)​ 下,@被保留用于邻近搜索(Proximity Search)​ 运算符(例如 "word1 word2"@10),用来判断多个词是否在指定距离内出现。如果它没有以这种预期格式出现,数据库引擎就无法正确解析你的查询语句,从而导致报错。

应该要替换@字符:

$search_term = "user@example.com";
$cleaned_term = str_replace('@', ' ', $search_term);

Comments

No comments yet. Why don’t you start the discussion?

发表回复