Zend_Db_Expr

在zendframework中使用Db类时,框架会自动给sql语句添加引号以防止数据库攻击 ,这就导致了一个问题,用户无法使用zend db类使用mysql的内置函数(方法,存储过程等)。好在zend框架提供了一个类Zend_Db_Expr,此类的构造函数会告诉框架不要对它所转化的类型进行添加引号的操作

    public function setBatchDelete($orderIds) {
        $flag = YCL_Order::FLAG_DELETED;
        $updateTime = time();
        $data = array(
            'flag' => new Zend_Db_Expr("flag | $flag"),
            'update_time' => $updateTime
        );   
        $db = $this->getAdapter();
        $where = $db->quoteInto('service_order_id IN (?)',$orderIds);
        $this->update($data,$where);
    }

上面的例子 左边的flag是数据库中的flag。


   $select=$db->select();
   $select->from("testtable","*");
   $select->where($db->quotInto("date>=?",new Zend_Db_Expr("UNIX_TIMESTAMP()"));
   $db->fetchAll($select);

框架不会对UNIX_TIMESTAMP()添加引号,从而让用户能正常使用此函数。


You also can create an object of type Zend_Db_Expr explicitly, to prevent a string from being treated as a column name.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值