反 sql-magento 中的注入

anti sql-injection in magento

我搜索了反 sql 注入代码。以下代码是我采用的。 我想再次确认以下 php 代码可以防止 sql-injection

$sql_select = "
SELECT
    *
FROM main_tbl
WHERE 
(
  (((main_tbl.from_id = :sender_id) AND (main_tbl.to_id = :to_id)) 
    OR ((main_tbl.to_id = :sender_id) AND (main_tbl.from_id = :to_id)))
  AND
  (main_tbl.last_date > :lasttime)
);
";

$binds = array(
    'sender_id' => $sender_id, 
    'to_id' => $to_id,
    'sender_id' => $sender_id,
    'to_id' => $to_id,
    'lasttime' => $lasttime
);
$resource = Mage::getModel('core/resource');
$read = $resource->getConnection('core_read');
$results = $read->fetchAll($sql_select, $binds);

是的,此代码未显示任何漏洞,应该是安全的。一个好的经验法则是始终验证用户输入。

但是你的代码有点缺陷,但从你对你问题的评论来看,我假设你已经知道了。