0

从to更新Zend 1.12.11.12.3x_debug on制作OLD_PASSWORD.default

我重新运行了一个曾经无缝运行的程序,现在它有一个致命的PDOException,详细信息如下:

错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'place_fcb.userid' in 'group statement'

实际 SQL 查询:

SELECT `C`.* 
FROM (SELECT `place_fcb`.* FROM `place_fcb`) 
AS `C` 
WHERE (place_type_id != '176') 
GROUP BY place_fcb.userid
HAVING (place_fcb.pda >= '2009-12-21') 
AND (place_fcb.pda <= '2010-01-20')

Zend_Db_table_Abstract:

 public function getPlacefcb($start_date = '', $end_date = '', $r_id = '')
    {
        $sub_sql = $this->select()->from('place_fcb');

        $select = $this->select()
            ->setIntegrityCheck(false)
            ->from(array('C' => new Zend_Db_Expr('('.$sub_sql.')')))
            ->where("place_type_id != '176'")
            ->group('place_fcb.userid');

        if($start_date != '')
            $select->having('`place_fcb`.`pda` >= ?', $start_date);

        if($end_date != '')
            $select->having('`place_fcb`.`pda` <= ?', $end_date);

        if($region_id != '')
            $select->having('`place_fcb`.`r_id` = ?', $r_id);

        return $rowset = $this->fetchAll($select);
    }

place_fcb 的 MySQL:

place_fcb 是一个视图而不是一个表。它有以下相关领域

place_id
r_id
place_type_id
pda
userid

我可以通过将 SQl 语句更改为:删除异常并返回相同的结果:

    SELECT `C`.* 
    FROM (SELECT `place_fcb`.* FROM `place_fcb`) 
    AS `C` 
    WHERE (place_type_id != '176') 
    GROUP BY userid
    HAVING (pda >= '2009-12-21') 
    AND (pda <= '2010-01-20')

IE。删除所有表后缀...

但是我将如何用 Zend 修复它?为什么会突然出错?

4

1 回答 1

1

为什么您的查询使用子查询:

->from(array('C' => new Zend_Db_Expr('('.$sub_sql.')')))

而不是简单地:

->from('place_fcb')

place_fcb用前者,外查询没有表;因此,合格的引用会失败(而且总是会失败,所以我看不出它在这次升级之前是如何为你工作的)。

如果您坚持保留子查询,则可以将子查询的别名从 重命名'C''place_fcb',尽管从长远来看这可能会引起混淆;最好将合格的引用从 重命名'place_fcb''C'

于 2013-07-09T07:41:10.720 回答