简体   繁体   中英

Zend framework Database config to get Resultset

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

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM