此结果是仅向前的结果集,不支持向前移动后调用 rewind() - Zend [英] This result is a forward only result set, calling rewind() after moving forward is not supported - Zend

查看:16
本文介绍了此结果是仅向前的结果集,不支持向前移动后调用 rewind() - Zend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Zend 应用程序中,我使用 ZendDbTableGatewayZendDbSql 从 MySQL 数据库中检索数据数据,如下所示.

In Zend app, I use ZendDbTableGateway and ZendDbSql to retrieve data data from MySQL database as below.

模型 -

public function getCandidateEduQualifications($id)
{
    $id  = (int) $id;

    $rowset = $this->tableGateway->select(function (SqlSelect $select) use ($id)
    {
        $select->where
            ->AND->NEST->equalTo('candidate_id', $id)
            ->AND->equalTo('qualification_category', 'Educational');
    });

    return $rowset;
}

查看 -

我只是在视图中迭代 $rowset 和 echo.但是当尝试回显两次或更多次时它会出错.单次迭代有效.

I just iterate $rowset and echo in view. But it gives error when try to echo two or more times. Single iteration works.

这个结果是一个只向前的结果集,在调用rewind()之后不支持前进

This result is a forward only result set, calling rewind() after moving forward is not supported

我可以通过将其加载到视图中的另一个数组来解决它.但这是最好的方法吗?有没有其他办法可以解决这个问题?

I can solve it by loading it to another array in view. But is it the best way ? Is there any other way to handle this ?

$records = array();
foreach ($edu_qualifications as $result) {
    $records[] = $result;
}

编辑 -

$resultSet->buffer(); 解决了这个问题.

推荐答案

您收到此 Exception 因为这是预期的行为.Zend 使用 PDO 来获取它的 ZendDbResultSetZendDbTableGatewayTableGateway 返回的结果集.PDO 结果集默认使用只进游标,这意味着您只能循环一次.

You receive this Exception because this is expected behavior. Zend uses PDO to obtain its ZendDbResultSetResultset which is returned by ZendDbTableGatewayTableGateway. PDO result sets use a forward-only cursor by default, meaning you can only loop through the set once.

有关游标的更多信息,请查看维基百科这个 文章.

For more information about cursors check Wikipedia and this article.

作为 ZendDbResultSetResultset 实现 PHP Iterator 您可以使用 ZendDbResultSetResultset:toArray() 方法或使用 iterator_to_array() 函数.在潜在的大型数据集上使用此函数时请务必小心!关于游标的最好的事情之一正是它们避免一次性引入所有内容,以防数据集太大,因此有时您不想一次将其全部放入数组中.

As the ZendDbResultSetResultset implements the PHP Iterator you can extract an array of the set using the ZendDbResultSetResultset:toArray() method or using the iterator_to_array() function. Do be careful though about using this function on potentially large datasets! One of the best things about cursors is precisely that they avoid bringing in everything in one go, in case the data set is too large, so there are times when you won't want to put it all into an array at once.

这篇关于此结果是仅向前的结果集,不支持向前移动后调用 rewind() - Zend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆