PreparedStatement 如何避免或防止 SQL 注入? [英] How does a PreparedStatement avoid or prevent SQL injection?

查看:25
本文介绍了PreparedStatement 如何避免或防止 SQL 注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 PreparedStatements 避免/防止 SQL 注入.它是如何做到的?使用 PreparedStatements 构造的最终表单查询是字符串还是其他形式?

I know that PreparedStatements avoid/prevent SQL Injection. How does it do that? Will the final form query that is constructed using PreparedStatements will be a string or otherwise?

推荐答案

SQL 注入的问题在于,用户输入被用作 SQL 语句的一部分.通过使用准备好的语句,您可以强制将用户输入作为参数的内容进行处理(而不是作为 SQL 命令的一部分).

The problem with SQL injection is, that a user input is used as part of the SQL statement. By using prepared statements you can force the user input to be handled as the content of a parameter (and not as a part of the SQL command).

但是,如果您不使用用户输入作为准备好的语句的参数,而是通过将字符串连接在一起来构建 SQL 命令,则即使使用准备好的语句,您也仍然容易受到 SQL 注入的影响.

But if you don't use the user input as a parameter for your prepared statement but instead build your SQL command by joining strings together, you are still vulnerable to SQL injections even when using prepared statements.

这篇关于PreparedStatement 如何避免或防止 SQL 注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆