【问题标题】:Database expression not used in query查询中未使用数据库表达式
【发布时间】:2010-12-01 19:58:42
【问题描述】:

谁能告诉我为什么我的表达式没有在下面的查询中使用?

SELECT accountreset.* FROM accountreset WHERE (reset_id = '34') LIMIT 1

public function findByResetId($resetId, $model = null) {
    $result = null;
    if (isset($resetId)) {
        $select = $this->getDao()->select(
            array('expiration' => new Zend_Db_Expr('UNIX_TIMESTAMP(expiration)'))
        );
        $select->where('reset_id = ?', $resetId);
        $row = $this->getDao()->fetchRow($select);
        if (null != $row) {
            if (!($model instanceof Stage5_Model_PasswordResetter)) {
                $model = new Stage5_Model_PasswordResetter();
            }
                           // vul het model object
            $model->setResetId($row->reset_id);
            $model->setUserId($row->user_id);
            $model->setExpiration($row->expiration);
            $result = $model;

        }
    }
    return $result;

}

【问题讨论】:

    标签: zend-framework zend-db


    【解决方案1】:

    您的Zend_Db_Expr 应该进入from() 方法而不是select()

    $select = $this->getDao()
                   ->select()
                   ->from( 
                       $this->getDao()->info('name'), 
                       array('expiration' => new Zend_Db_Expr('UNIX_TIMESTAMP(expiration)'))
                    );
    

    【讨论】:

    • 这里的问题是现在我必须在我的 from 子句中添加我想要的所有字段。因为否则它只会返回一个字段。
    • @sanders 你可以在你的字段数组()中添加一个“*”。
    猜你喜欢
    • 2011-09-26
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 2015-08-25
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多