I have this SQL query that keeps shooting me an error:
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 ‘OR
descriptionIN BOOLEAN MODE) ORDER BYdatetimeASC LIMIT 0,20′ at line 4
This is the query I’m attempting to run:
$items = $itemsClass->getAll($start , $limit, " `status` = 'active' AND MATCH (".sql_quote($s).") AGAINST (`name` OR `description` IN BOOLEAN MODE) ".$whereQuery, "$order");
Why: I’m working on a search function for a website and when we search for a certain keyword (i.e. cake), it shows the relavent items. But, when we search for ‘cook’ which is also in the same title/ description as the cake item, it doesn’t result any results and says it’s empty.
I can’t seem to figure out why I’m getting this error for the query. I’m just trying to find a solution to my problem. I’m using MySQL 5.1.66.
First of all, you put column names in the
MATCH()function, and patterns in theAGAINST()function. You’re doing it the wrong way around.Second, searches across multiple columns are implicitly “OR” comparisons, in that a keyword match in any of the indexed columns counts as a match.
So you should use:
The columns you name in the
MATCH()function must be all the columns you defined in your fulltext index, and in the same order as they appear in the index.Only if you defined two separate fulltext indexes, one for each column, then you need to use two separate predicates.