我试图围绕现有的Zend_Db select语句包装count(*)查询,但我能得到的只有:
SELECT `t`.*, COUNT(*) AS `TotalRecords` FROM (SELECT ....) AS `t`
但是我喜欢摆脱t。*因为我只需要计数(*)。
到目前为止,这是我的代码:
$db = Zend_Registry::get('db');
$select = $dbmodel->getSomething(); //zend select object
$outterSelect = new Zend_Db_Select($db);
$outterSelect->from($select)->columns(array('TotalRecords' => new Zend_Db_Expr('COUNT(*)')));
echo $outterSelect->__toString();
感谢任何帮助!
答案 0 :(得分:5)
您可以简单地写一下:
$outterSelect->from($select, 'COUNT(*) as TotalRecords');