While fetching more than 300k records in mysql, i'm getting error like this
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in
Project\system\database\drivers\mysqli\mysqli_result.php on line 229.
I have increased memory_limit up to 1024M and changed to -1 also.
i can't find the solution till
Use PHP Generators instead
function getData()
{
$sql = 'SELECT * FROM table';
$q= $this->conn->prepare($sql);
$q->execute();
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
yield $row;
}
}
foreach ($this->getData() as $record) {
//
}
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.