![](/img/trans.png)
[英]For prevention of sql injection, should I use PDO 'prepare' when querying the DB, or only when updating?
[英]Zend db - When should I quote to avoid sql injection?
我对何时自动引用框架以及何时不quote
变量感到困惑。 例如,据我所知,它不会在where
子句中引用(除非您使用额外的参数?)。
是否有一个指导/备忘单引用的时候一定要手动quote
在基本的CRUD操作?
谢谢。
对我而言,基本的“经验法则”如下:
"SELECT * from TABLE WHERE value=$value"
,则必须先将其引号。 $select->where('value = ?', $value');
或诸如array('value' => $value)
之类的值array('value' => $value)
,框架将为您引用该值。 希望能帮助到你,
永远不要自己构建查询字符串,始终让Zend_Db为您完成。 也就是说,不要通过自己构建字符串来指定where子句(等等):
$where = 'id = ' . $_REQUEST['id'] . ' and thing = ' . $_REQUEST['thing'];
$select->where($where);
而是这样做:
$select
->where('id = ?', $_REQUEST['id'])
->where('thing = ?', $_REQUEST['thing']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.