ZF2-281: Cannot Count rows in a MySQLi Result Set
I have an issue with the TableGateway, ResultSet classes. If I call after a select the count() method, it will always return 0 (An example is shown below). The first row can be accessed by current()-stmt without a problem. Furthermore it is not possible to loop twice over the same result set with rewind(), current() and next(). Even going through the resultSet after a call to count() is not possible. Here is a short code snipped to demonstrate the error (short):
use Zend\Db\TableGateway\TableGateway; use Zend\Db\Adapter\Adapter; $adapter = new Adapter(array( 'driver' => 'Mysqli', 'database' => , 'username' => , 'password' => )); $tab = new TableGateway(, $adapter); $resultSet = $tab->select(); echo $resultSet->count(); // will always return 0
I belive that the error is in this case in Zend\Db\Adapter\Driver\Mysqli\Result class. The result ressource is a mysqli_stmt class, but no mysqli_stmt::store_result() is called and therefore the result set is never transfered from the query and can only be accessed once. A possible fix can be found in Pull Request #1080 https://github.com/zendframework/zf2/pull/1080.