简体   繁体   English

Zend框架数据库配置以获取结果集

[英]Zend framework Database config to get Resultset

I have setup zf2 DB adapter for mysqli, using the below configuration: 我使用以下配置为mysqli设置了zf2 DB适配器:

'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. 连接有效,我可以查询数据库,我的问题是我得到的是'Zend \\ Db \\ Adapter \\ Driver \\ Mysqli \\ Result',而不是我想要的结果集对象。

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 上面的代码返回Zend \\ Db \\ Adapter \\ Driver \\ Mysqli \\ Result对象

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 timdev提供的文档链接有助于解决此问题,如果存在此代码,则可以将MysqliResult对象转换为结果集

if ($result instanceof ResultInterface && $result->isQueryResult()) {
    $resultSet = new ResultSet;
    $resultSet->initialize($result);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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