gpt4 book ai didi

php - symfony2 Doctrine 在不创建完整结果数组的情况下获取

转载 作者:行者123 更新时间:2023-12-01 22:22:03 25 4
gpt4 key购买 nike

我正在寻找使用 Doctrine 导出到 csv 文件。然而,数据可能相当大。因此我不想将结果输出到完整的数组。我想迭代地遍历结果。

我尝试过在这里查看 doctrine docs

PHP 看起来像这样

    $result = mysql_query("SELECT * FROM bigtable");
while($row = mysql_fetch_assoc($result)) {
// do code iteratively here
}

不知道你如何在 symfony2 的 Doctrine 中做同样的事情

最佳答案

This is from the doctrine documentation about batch processing :

$q = $this->_em->createQuery('select u from MyProject\Model\User u');
$iterableResult = $q->iterate();
foreach ($iterableResult AS $row) {
// do stuff with the data in the row, $row[0] is always the object

// detach from Doctrine, so that it can be Garbage-Collected immediately
$this->_em->detach($row[0]);
}

'select u ....相当于您的SELECT * ...

关于php - symfony2 Doctrine 在不创建完整结果数组的情况下获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com