phpmysqlmatchwildcardagainst

How to implement a wildcard in a MySQL MATCH (...) AGAINST (...) query


I have a MySQL query in PHP, using MATCH and AGAINST to filter results. I'm trying to get a wildcard after $string so the next character can be anything.

"SELECT *
 FROM $table
 WHERE MATCH (message) AGAINST('$string%' IN BOOLEAN MODE)"

Solution

  • Use * instead of % as a wildcard when using MATCH (...) AGAINST (...):

    "SELECT * FROM $table WHERE MATCH (message) AGAINST('$string*' IN BOOLEAN MODE)"