I have a script to save large datasets from a mssql query into an array, however it will fails into : "[23-Apr-2009 11:31:30] PHP Fatal error: Allowed memory size of 786432000 bytes exhausted (tried to allocate 40 bytes) in /gui/include/MssqlDB.php on line 61
Actually, the total dataset I want to fetch is about 54M, and the memory limit I set in php.ini is already 750M.
Here is the method I used in my MssqlDB class:
Code: Select all
function query ( $query_str )
{
global $g_logging;
$result = mssql_query($query_str);
if ($result === FALSE)
{
$g_logging->error("mssql query '$query_str' failed");
return FALSE;
}
else
{
$g_logging->debug("Successfully send mssql query '$query_str' ");
return $result;
}
}
function get_result( $query_str )
{
global $g_logging;
$result = array();
$queryID = $this->query($query_str);
if ($queryID !== FALSE)
{
if (mssql_num_rows($queryID) >0)
{
while ($row=mssql_fetch_row($queryID))
{
$result[]=$row;
}
}
else
{
$g_logging->info("No result returned by query '$query_str' ");
}
}
else
$result=FALSE;
if (mssql_free_result($queryID) === FALSE)
$g_logging->error("failed to free mssql resource");
return $result;
}
$db = new MssqlDB;
$queryStr = "xxxxxxxxxx";
$db->get_result($queryStr);
Actually, I tried to use some procedural approach to test this:
Code: Select all
$result = mssql_query($queryStr);
while ( $row = mssql_fetch_row( $result) )
{
fwrite($file_pointer, $row);
}
Now, my question is: if the $result (mssql or mysql or any other database resource ) is saved in memory by php engine, why my first approach fails?
Thank you!