设为首页 加入收藏

TOP

Zend_Db_Expr
2015-07-24 10:55:35 来源: 作者: 【 】 浏览:2
Tags: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.
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇11.2.0.4单实例的dbinstance启动.. 下一篇用热备+归档恢复损坏的非系统表空..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)