为zend准备好的陈述

时间:2013-11-25 11:29:52

标签: php mysql zend-framework prepared-statement

我正在使用zf1。模态查询是:

$select = $postTable->select()
        ->setIntegrityCheck(false)
        ->from('posts')
        ->joinLeft('users', 'users.id = posts.user_id', array('post_first_name' => 'first_name'))
        ->where('posts.property_id = ?', $id);

$postTable->fetchAll($select);

我正在尝试为此查询使用预准备语句。我还没想出如何将它转换为预处理语句,所以请通过将此查询转换为预处理语句来帮助我。

1 个答案:

答案 0 :(得分:2)

只需使用如下

 $params = array($property_id);

   $sql = "SELECT post_first_name as first_name " .
                 "FROM posts" . 
            "left join users on users.id = posts.user_id WHERE posts.property_id =  ?";
           $stmt = $db->query($sql, $params);
            $dealers = $stmt->fetchAll();

上面只是过程代码,您可以根据需要设置列名和表名。

希望这对您有所帮助。

相关问题