我收到错误但我似乎无法自己发现错误。 也许你们中的某些人知道解决方案。
我的查询:
return $db->fetchAll("SELECT DISTINCT *,
MATCH(k.naam, k.plaats)
AGAINST('{$newQ}'
IN BOOLEAN MODE)
as score
FROM klant k
WHERE MATCH(k.naam, k.plaats)
AGAINST('{$newQ}' IN BOOLEAN MODE)
OR code = '{$q}'
AND bedrijf_id = '{$bedrijf}'
ORDER BY score DESC LIMIT " . intval($limit));
我的错误:
Message: SQLSTATE[42000]:
Syntax error or access violation: 1064 syntax error,
unexpected $end, expecting FTS_TERM or FTS_NUMB or '*',
query was: SELECT DISTINCT *, MATCH(k.naam, k.plaats) AGAINST('*' IN BOOLEAN MODE) as score FROM klant k WHERE MATCH(k.naam, k.plaats) AGAINST('*' IN BOOLEAN MODE) OR code = '' AND bedrijf_id = '1' ORDER BY score DESC LIMIT 3
查询看起来对我来说绝对没问题,有人能指出我应该看的地方吗?
答案 0 :(得分:2)
我今天遇到了同样的问题。我发现原因是MATCH()参数的格式。因此,在您的情况下,导致错误的是您传入 {$ newQ} 的价值。
要找出MATCH()的语法,请查看:
http://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html
答案 1 :(得分:1)
match
返回一个double,而不是布尔值 - 您在where
子句中错过了对其返回值的限制:
return $db->fetchAll("SELECT DISTINCT *,
MATCH(k.naam, k.plaats)
AGAINST('{$newQ}'
IN BOOLEAN MODE)
as score
FROM klant k
WHERE MATCH(k.naam, k.plaats)
AGAINST('{$newQ}' IN BOOLEAN MODE)
HAVING relevance > 0 -- Missing from the OP
OR code = '{$q}'
AND bedrijf_id = '{$bedrijf}'
ORDER BY score DESC LIMIT " . intval($limit));