Zend_DB / Doctrine 可以保护我免受 SQL 注入吗?
在 Zend_DB 或 Doctrine 中使用准备好的语句是否可以保护我免受 SQL 注入?
示例:
$stmt = $db->prepare('SELECT * FROM users WHERE name = ? AND password = ?');
$rs = $stmt->execute('peter', 'secret');
或者我必须自己检查字符串和类型类型吗?
另一个快速说明:两者中哪一个最好?我只需要数据库抽象(带有语句、过程和事务)。
Does using prepared statements in Zend_DB or Doctrine protect me from sql injection?
example:
$stmt = $db->prepare('SELECT * FROM users WHERE name = ? AND password = ?');
$rs = $stmt->execute('peter', 'secret');
Or do I have to check strings and types types myself?
Another quickie: Which of the two is best? I only need the DB abstraction (w/ statements, procedures, and transactions).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
准备好的语句,无论是使用 Zend_Db、Doctrine 还是普通的旧 mysqli 完成的,都可以通过将查询结构与数据分离来保护您免受注入。这意味着,如果您准备一份根据用户名和密码选择用户的声明,则没有黑客能够提供将该声明转变为不同声明的数据。
只要确保查询本身是一个字符串常量即可。
至于你的第二个问题,Doctrine 和 Zend_Db 有不同的方法来适应不同的情况和不同的审美偏好。这里已经有几个关于该主题的问题。
Yes.
Prepared statements, whether done with Zend_Db, Doctrine or plain old mysqli, protect you from injection by separating the query structure from the data. This means that if you prepare a statement that selects users based on their name and password, no hacker will be able to provide data that turns that statement into a different one.
Just make sure that the query itself is a string constant.
As for your second question, Doctrine and Zend_Db have different approaches that fit different situations and different aesthetic preferences. There have already been several questions on the topic here.