我在我的類上創建了一個方法來獲取並存儲所需的SQL語句中的所有結果,並且它工作得很好。現在,在生產一些個月後,我遇到了這個錯誤:mysql_free_result()中的內存耗盡
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 3503272 bytes) in C:\xxpathxx\class.DGC_Gerais.php on line 0
正如我開始檢查,我跟蹤誤差爲mysql_free_result()
,但在評論這條線,它仍然doenst工作。
這裏的_fetch
方法:
PUBLIC static function _fetch($sql){
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0):
for($a=0 ; $linha = mysql_fetch_row($q) ; $a++){ // forEach row.
foreach($linha as $chave => $valor): // forEach field.
$result[$a][$chave] = $valor;
endforeach;
}
// mysql_free_result($q);
return $result;
else:
return false;
endif;
}
如果你的數據集對於你的內存來說太多了,你可能會考慮使用分頁。 –