从Zend 1.12.1
更新为1.12.3
并转为x_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是一个VIEW而不是一个表。它有以下相关领域
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')
即。删除所有表后缀......
但我如何用Zend修复它?为什么突然出错?
答案 0 :(得分:1)
为什么您的查询使用子查询:
->from(array('C' => new Zend_Db_Expr('('.$sub_sql.')')))
而不仅仅是:
->from('place_fcb')
对于前者,外部查询中没有place_fcb
表;因此,这些合格的引用失败了(而且总是如此,所以在升级之前我无法看到它是如何为你工作的。)
如果您坚持保留子查询,则可以将子查询的别名从'C'
重命名为'place_fcb'
,尽管这可能会导致长期混淆;最好将合格的引用重命名为'place_fcb'
到'C'
。