ZF2 - 如何在列()中使用SQL_CALC_FOUND_ROWS

时间:2013-04-16 12:07:05

标签: php mysql zend-framework zend-framework2

我正在尝试在查询中使用 SQL_CALC_FOUND_ROWS 。但是如果没有 AS Expression1

,我无法创建我的查询
$select = $this->getSql()->select();
            $select->columns(array("*", new Expression(" SQL_CALC_FOUND_ROWS *")));
            $select->join( array ( 
                    'c2h' => 'site_category2help_topic' ), 'c2h.help_topic_id = site_help_topic.help_topic_id', array ( 
                    "*" ) );
            $select->where( " c2h.category_id = $categoryId " );
            $select->limit($limit);
            $select->offset($offset);

结果:

SELECT site_help_topic.*, SQL_CALC_FOUND_ROWS * *AS Expression1*, c2h.* 

FROM site_help_topic 

INNER JOIN site_category2help_topic AS c2h 

ON c2h.help_topic_id = site_help_topic.help_topic_id 

WHERE c2h.category_id = 5 LIMIT '15' OFFSET '0'

IT应该是:

SELECT site_help_topic.*, SQL_CALC_FOUND_ROWS *, c2h.* 

FROM site_help_topic 

INNER JOIN site_category2help_topic AS c2h 

ON c2h.help_topic_id = site_help_topic.help_topic_id 

WHERE c2h.category_id = 5 LIMIT '15' OFFSET '0'

1 个答案:

答案 0 :(得分:1)

Sql \ Select有一个选项QUANTIFIER,您应该可以使用它而不是将其作为列名。

与此类似How to use SQL_CALC_FOUND_ROWS with Zend\Db\TableGateway