PHP/MYSQL match against query

9.1k views Asked by At

I am trying to run a match against query and it is not working. I created a full text index on the two fields. But am getting sql error right before word 'relationship". Here is sql:

"SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST (romance, relationship)";

I have also tried just searching against shdescript and just searching against ldescript but get same error. Also I've tried searchstring without spaces. As far as I know, you are supposed to have the words of the searchstring separated by commas in parentheses. What am I doing wrong? Thanks.

4

There are 4 answers

3
Scott Saunders On BEST ANSWER

Add quotes around your search string.

0
Lajos Arpad On
"SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST ('romance', 'relationship')";

Also make sure you protect yourself against the nasty SQL injection threat, read more here.

0
Andy Jones On

Try quoting your string (i.e 'romance' and 'relationship')

SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST ('romance', 'relationship')
0
Nick On

I believe your AGAINST must be in quotes. From:

http://dev.mysql.com/doc/refman/4.1/en/fulltext-search.html#function_match

AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a literal string, not a variable or a column name.