Mysql_real_escape_string() 警告混乱
echo mysql_real_escape_string($dbc, "string");
产生警告:
Warning: mysql_real_escape_string() expects parameter 1 to be string, object
given in **...**
因此,即使我给函数提供看起来明显是字符串对象的内容,它也不会将它们视为字符串。
这是怎么回事?
echo mysql_real_escape_string($dbc, "string");
Produces the warning:
Warning: mysql_real_escape_string() expects parameter 1 to be string, object
given in **...**
So even when I give the function what seem to be obviously string objects it's not seeing them as strings.
What's going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mysql_real_escape_string
仅采用字符串作为参数。就是这样。$string = mysql_real_escape_string('string')
如果要指定链接标识符,它是可选的第二个参数:
$string = mysql_real_escape_string('string', $dbc)
>mysql_real_escape_string
just takes a string for an argument. That's it.$string = mysql_real_escape_string('string')
If you want to specify the link identifier, it is the optional second argument:
$string = mysql_real_escape_string('string', $dbc)
检查文档。参数则相反(连接是可选的)。
Check the docs. The parameters go the other way around (connection is optional).
为什么要像下面这样向它传递两个参数?
试试这个,它应该有效。
Why are you passing two parameters to it like the following?
Try this, it should work.
通常当我们使用
mysql_real_escape_string
时,我们在处理SQL语句时,我们必须循环遍历每个字段,其中有些字段是空的,有些不是字符串。 错误表明该函数需要一个字符串,这意味着某些字段不是字符串,为了避免此警告,您必须执行检查:Normally when we use
mysql_real_escape_string
is when we dealing with an SQL statement, where we have to loop through each field, some of which are empty and some are not strings. The error says the function expects a string, meaning some fields are not strings, to avoid this warning you have to perform a check: