我正在使用 PHP
和 Zend Framework 2.3.3
。我使用了Paginator
来处理一个带有Union
的Select语句。
代码如下:
$where = new Where();
$where->like('value', "%$infoToSearch%");
$select = new Select();
$select->columns(array(new Expression('DISTINCT(id)')));
$select->from('products');
$select->where($where);
$select2 = new Select();
$select2->columns(array(new Expression('DISTINCT(id)')));
$select2->from('products_archive');
$select2->where($where);
$select->combine($select2);
$paginatorAdapter = new DbSelect($select, $this->getAdapter());
$paginator = new Paginator($paginatorAdapter);
$paginator->setCurrentPageNumber(1);
$paginator->setItemCountPerPage(10);
foreach($paginator as $product){
var_dump($product);
}
然后我得到了错误的产品数量。我查看了mysql查询日志,发现了这个查询:
( SELECT DISTINCT(id) AS Expression1 FROM `products` WHERE `value` LIKE '%3%' LIMIT 10 OFFSET 0 ) UNION ( SELECT DISTINCT(id) AS Expression1 FROM `products_archive` WHERE `value` LIKE '%3%' )
从您可以看到LIMIT 10 OFFSET 0
的位置是错误的。它应该在查询语句的结尾。这是一个Bug还是有解决问题的方法?