mysql真实转义字符串与LIKE不获取任何结果
我有一个 mysql 查询,
mysql_query("SELECT name,symbol FROM scode WHERE change='$change'
AND product='$product' AND series='$typeo'
AND (name LIKE '%$check%' OR symbol LIKE '%$check%') LIMIT 5");
它工作得很好,但是如果我尝试使用 mysql 字符串使用相同的查询,那么查询不会返回任何结果。 我尝试过这样
$query= sprintf("SELECT name,symbol FROM `scode` WHERE change='%s'
AND product='%s' AND series='%s' AND (name LIKE '%s' OR symbol LIKE '%s')
LIMIT 5",
mysql_real_escape_string($change),
mysql_real_escape_string($product),
mysql_real_escape_string($typeo),
mysql_real_escape_string($check),
mysql_real_escape_string($check));
$fetch= mysql_query($query);
如何才能使查询有效?有人可以帮助我吗?谢谢。
I have a mysql query
mysql_query("SELECT name,symbol FROM scode WHERE change='$change'
AND product='$product' AND series='$typeo'
AND (name LIKE '%$check%' OR symbol LIKE '%$check%') LIMIT 5");
It works Perfectly but If I try to use the same query using mysql string then query is not returning any result.
i tried like this
$query= sprintf("SELECT name,symbol FROM `scode` WHERE change='%s'
AND product='%s' AND series='%s' AND (name LIKE '%s' OR symbol LIKE '%s')
LIMIT 5",
mysql_real_escape_string($change),
mysql_real_escape_string($product),
mysql_real_escape_string($typeo),
mysql_real_escape_string($check),
mysql_real_escape_string($check));
$fetch= mysql_query($query);
How can I make the query that will work? Can some help me? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,不,这是行不通的,因为在第一个中你做了一个
LIKE %term%
,在第二个你做了一个LIKE term
。尝试添加%%
,如下所示:Well no it wouldn't work, because in the first you do a
LIKE %term%
, in the second you do aLIKE term
. Try adding%%
around, like this:将其添加到 mysql_query 的末尾,它将显示错误消息是什么
Add this to the end of your mysql_query and it will show you what the error message is
我查了一下,发现一个问题。看起来 mysql 试图将“change”列解析为关键字。尝试将“更改”放入``。
I have checked it and found one issue. Looks like mysql trying to parse "change" column as a keyword. Try to put "change" in ``.