mysql 针对通配符的查询
我在 php 中有一个 mysql 查询,使用 match / against 来过滤结果。我试图在 $string 之后获取通配符,以便下一个字符可以是任何内容。帮助?
"SELECT * FROM $table WHERE MATCH (message) AGAINST('$string%' IN BOOLEAN MODE)"
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 anything. Help?
"SELECT * FROM $table WHERE MATCH (message) AGAINST('$string%' IN BOOLEAN MODE)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
MATCH (...) AGAINST (...)
时,使用*
而不是%
作为通配符:Use
*
instead of%
as a wildcard when usingMATCH (...) AGAINST (...)
:不要将变量嵌入到双引号字符串中,这样就完成了:
话虽如此,我无法确认这是有效的 SQL。但至少它会确保你的变量被正确扩展,如果它不起作用,那也不是因为 PHP 的原因。
为了以防万一这个提醒有用,千万不要忘记转义进入查询的数据 。
Don't embed variables into double-quoted strings and you're set:
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.