【问题标题】:MySQL/PHP syntax error - looks fine to meMySQL/PHP 语法错误 - 对我来说看起来不错
【发布时间】:2011-03-26 19:23:46
【问题描述】:

我正在脚本中执行全文搜索查询,但遇到了问题。所以我添加了一个快速的“echo mysql_error”,因为我得到了不应该得到的错误结果。这是实际输入的查询:

(*Sending these args respectively: 'announc_threads', 'subject', 'replying'*)

public function searchFulltext ($table, $field, $against) {
     $query = "SELECT TID, authorUID, timeStarted, 
               WHERE MATCH (".$field.") AGAINST ('$against') AS score
               FROM ".$table."
               WHERE MATCH (".$field.") AGAINST ('$against')";

这是我得到的错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE MATCH (subject) AGAINST ('replying') AS score FROM announc_threads WHERE M' at line 1

查看错误,一切看起来都很好。我在查询中遇到的最大问题是单引号/双引号和使用变量(它似乎总是会改变它想要的) - 但即使那些看起来不错,字符串周围的单引号,表/字段名称周围没有引号 - grrr - 你呢有什么不对吗?

感谢您的帮助。

【问题讨论】:

  • 哦,是的,我仔细检查了我在正确表中搜索的字段是否有全文索引。

标签: php mysql full-text-search


【解决方案1】:

您的select 子句中的字段列表中有一个where

我想您打算选择分数,并从您的 where 子句中复制粘贴 match...against 内容,因此,where 可能是复制粘贴错误,应该被删除:

$query = "SELECT TID, authorUID, timeStarted, 
           MATCH (".$field.") AGAINST ('$against') AS score
           FROM ".$table."
           WHERE MATCH (".$field.") AGAINST ('$against')";

(我删除的where位于该部分代码的第二行开头)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多