开发者

mysql query against wildcard

I have a mysql query in php, using match / against to filter results. Im trying to get a wildcard after $string so the next character can be anythi开发者_如何学Gong. Help?

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


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

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


Don't embed variables into double-quoted strings and you're set:

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

That being said, I can't confirm this is valid SQL. But at least it'll ensure your variable is expanded properly and if it doesn't work then it won't be because of PHP.

And just in case this reminder will be useful, nevar forget to escape data that goes into a query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜