我是否需要在数据库数据上使用 mysql_real_escape_string 来重新插入?
您好,提前致谢。
我正在从数据库检索数据。数据在添加到数据库时已经经过了mysql_real_escape_string
。
检索后,我将其与原始变量进行比较,根据结果,我可能会将原始数据库数据重新插入到数据库中的另一个不同的字段中。
我的问题是,我是否必须对从数据库获取的数据使用 mysql_real_escape_string ?
我认为是的,因为数据可能包含需要转义的字符,并且我认为反斜杠不存储在数据库中。
我的代码是:
if(isset($row['location_uri']) && $row['location_uri'] != $location_uri)
{
$session_previous_page = $row['previous_page_uri'];
}
else
{
$session_previous_page = $row['location_uri'];
}
另外,在将数据库数据与原始数据(例如来自 $_SERVER['REQUEST_URI']
进行比较之前,我是否应该对数据库数据执行任何操作?
感谢您提供的任何帮助。
Hello and thanks in advance.
I am retrieving data from the db. The data already went through mysql_real_escape_string
when it was added to the db.
Once retrieved I am comparing it to a raw variable and depending upon the result I may be re-inserting the original db data back into the db into another, different, field.
My question is, do I have to use mysql_real_escape_string
on this data I got from the database?
I think yes as the data could contain characters that need to be escaped and I think the backslashes are not stored in the db.
My code is:
if(isset($row['location_uri']) && $row['location_uri'] != $location_uri)
{
$session_previous_page = $row['previous_page_uri'];
}
else
{
$session_previous_page = $row['location_uri'];
}
Also, should I do anything with the db data before I compare it to the raw data, say from $_SERVER['REQUEST_URI']
?
thanks for any help you can give.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该重新应用它。转义函数放入斜杠等,因此它是有效的 SQL 语法。这些斜杠实际上并未存储在数据库中。
You should re-apply it. The escaping functions put in slashes, etc. so it is valid SQL syntax. Those slashes aren't actually stored in the database.
是的。您回答了自己的问题 - 因为特殊字符在读取时被转换,所以您需要在写入时重新转义它们。
我不确定您关于
$_SERVER['REQUEST_URI']
的具体问题。但如果你永远不应该相信这些变量。因此,如果您在数据库查询中比较它,至少我建议转义它。Yes. You answered your own question - because special characters are converted on read, you need to re-escape them on write.
I am not sure your exact question regarding
$_SERVER['REQUEST_URI']
. But if you should never trust these variables. So if you are comparing it in a DB query, at the least, I suggest escaping it.