zendframework/zend-db

Zend\Db\ResultSet\ResultSet->current() returns false instead of NULL

Closed this issue · 9 comments

This problem was there in version 2.7. It was fixed in 2.8, but came back in 2.9.

  • Database: 10.0.35-MariaDB
  • PHP version: 7.2.7
  • Zend Db version: 2.9.3

To reproduce, use a database with some empty table, and execute:

$myAdapter = new \Zend\Db\Adapter\Adapter([
    'host'      => 'mariadb',
    'driver'    => 'Mysqli',
    'username'  => 'devppl',
    'password'  => '******',
    'database'  => 'mydatabase',
    'charset'   => 'utf8',
    'options'   => ['buffer_results' => true]
]);

$tableGateway = new \Zend\Db\TableGateway\TableGateway('myEmptyTable', $myAdapter);
$row = $tableGateway->select('myField = 999')->current();
var_export($row);

Expected result would be NULL, I get false instead.

I noticed that when I set buffer_results to false, I don't have the bug.

I think the commit that actually broke the fonctionnality is this one, it returns false in there and it should not because the signature says it should be null (or array):

8276cf6#diff-86b3a79320eb564e46456a1b75003271R197

@willy0275 I confirm this bug has been introduce by #255 and released in 2.9.0. I'm working on a fix.

Maybe this is related with #325

After a quick look, it seems like the same resulting bug but not the same bug as the method HydratingResultSet->current() is not using the code in the abstract class. So it seems it's just a coincidence and not really related.

@willy0275 I just sent the PR #334, please check and let me know. Thanks!

Looks great, thanks!

@willy0275 it seems there are some inconsistencies for other adapter, apart Mysqli. I'm working on it and let you know asap.

@willy0275 I closed #334 in favor of #337. Now the solution is directly in the mysqli adapter. Can you check? Thanks!