SQL全文搜索-“ where子句”中的未知列“ test”

时间:2018-10-04 08:22:17

标签: mysqli joomla

我正在尝试使用以下查询在Joomla系统中进行全文搜索:

SELECT `id`,`user_id`,`article_id`,`body`,`created_time`
FROM `#__user_notes`
WHERE (`user_id` = '660' AND `article_id` IN (23, 24) AND `id` < '385') 
OR (MATCH (body) AGAINST (`test`) AND `id` < '385' AND `user_id` = '660')
ORDER BY id DESC LIMIT 10

抛出此错误:

JDatabaseExceptionExecuting: Unknown column 'test' in 'where clause'

在没有全文搜索行的情况下工作正常:

OR (MATCH (body) AGAINST (`test`) AND `id` < '385' AND `user_id` = '660')

我已将ENGINE设置为MYISAM,因为此答案建议fulltext query in joomla

1 个答案:

答案 0 :(得分:2)

您应该从查询中删除反引号。

OR (MATCH (body) AGAINST (`test`) AND `id` < '385' AND `user_id` = '660')

上方应替换为

OR (MATCH (body) AGAINST ('test') AND `id` < '385' AND `user_id` = '660')

Mysql使用反引号作为列名,但是test是您要搜索的文本。

因为您正在使用Joomla,所以在Joomla中应该使用$db->quoteName而不是$db->quotequoteName用于转义列名,quote用于值