将IF子句添加到zend框架1数据库表选择对象

时间:2015-04-02 21:50:04

标签: php mysql zend-framework

这是我的sql:

    SELECT id,`status`,IF(`status` = 'active', 'deleted','active') AS `status-use`
    FROM categories

这是我的代码:( ActionResourceModelZend_Db_Table

            $dbTable = $this->getActionResourceModel();
            $select = $dbTable->select();
            $select->from($dbTable,$this->getQueryColumns());
            $select->order($orderClause.' '.$orderSpec);

如何添加到我的选择对象:

IF(`status` = 'active', 'deleted','active') AS `status-use`

2 个答案:

答案 0 :(得分:0)

您的选择应如下所示:

$dbTable = $this->getActionResourceModel();
$select = $dbTable->select();
$select->from(
        $dbTable, 
        array(
            'status-use' => new Zend_Db_Expr("IF(`status` = 'active', 'deleted','active')"
        )
);

答案 1 :(得分:-1)

您可以从Zend_Db_Table扩展并定义创建此查询的函数。你可以看到Zend_Db_Table函数,如joinfrom等,以设计你的特殊类