何时使用 mysql_real_escape_string?
我什么时候应该使用 mysql_real_escape_string?
仅当我将行插入数据库时才出现这种情况吗?或者只有当我有用户输入时?
谢谢
When should i use mysql_real_escape_string?
Is it only when i'm inserting rows into a database? Or only when i have user input?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
每当您构建将针对数据库运行的查询时,您都应该使用 mysql_real_escape_string()。用于构建数据库查询的任何用户输入都应通过此函数运行。这将防止sql注入攻击。
在这方面,用户输入是您最关心的领域。
You should use mysql_real_escape_string() whenever you're building a query that will be run against the database. Any user input that is being used to build a database query should be run through this function. This will prevent sql injection attacks.
User inputs are your big area of concern when it comes to this.
当您将字符串值插入 SQL 语句并且使用 MySQL API 时,您应该使用 mysql_real_escape_string。
应该是:
但是您还应该考虑将 PDO 与准备好的语句和绑定参数一起使用
mysql_real_escape_string
。这降低了出错的风险。You should use mysql_real_escape_string when you are inserting the value of a string into an SQL statement, and you are using the MySQL API.
Should be:
However you should also consider using PDO with prepared statements and bind parameters instead of
mysql_real_escape_string
. This reduces the risk of errors.除了整数之外,您还可以使用
intval()
always, apart from integers, there you use
intval()
它会简单地过滤表单数据中包含的所有特殊字符,以防止 SQL 注入(SQL 注入是一种黑客工具,通过对表单数据进行一些查询来攻击网站)
It will simply filter all special character which included in form data to prevent from SQL injection(SQL injection is a hacker tool for hacking website through some queries with form data}