Question

I have setup zf2 DB adapter for mysqli, using the below configuration:

'db' => array(
    'driver'         => 'Mysqli',
    'database' => 'db_name',
),
'service_manager' => array(
    'factories' => array(
        'Zend\Db\Adapter\Adapter'
        => 'Zend\Db\Adapter\AdapterServiceFactory',
    ),
    'aliases' => array(
        'db' => 'Zend\Db\Adapter\Adapter',
    ),
),

and using below code to create the connection:

$sm = $this->getServiceLocator();
$this->adapter = $sm->get('db');

The connection works and I can query database, my problem is that I am getting 'Zend\Db\Adapter\Driver\Mysqli\Result' instead of a resultset object which I want.

Thanks in advance

EDIT: code used for querying DB:

$this->adapter->query("SELECT * FROM `users`")->execute();

The code above returns a Zend\Db\Adapter\Driver\Mysqli\Result object

Was it helpful?

Solution

The link to documentation provided by timdev helped solve the problem, if this code is present you turn the MysqliResult object into a Result set

if ($result instanceof ResultInterface && $result->isQueryResult()) {
    $resultSet = new ResultSet;
    $resultSet->initialize($result);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top