Im trying to load large amount of data from Mysql to array but our server memory limit is too low for it. I can increase this limit but i guess it is not solution. I need better solution .. some type of cycle or what.
My actuall code:
$sql = "SELECT * FROM $tables";
$response = array();
$result = mysql_unbuffered_query( $sql );
while( $row=mysql_fetch_array( $result ))
{
$response[] = (
array(
"id" => $row['code'],
"name" => $row['name']
)
);
}
Using of mysql_unbuffered_query() will improved my situation but not at all.
Actually im loading about 1 000 rows.
UPDATE
$sql = "SELECT 'code','name' FROM $tables";
$response = array();
$result = $this->con->prepare($sql);
echo self::convert(memory_get_usage(true)); // 512kb
$result->execute();
echo self::convert(memory_get_usage(true)); // 21.25 mb
$array = $result->fetchAll();
// here script fails -> due to out of memory
foreach($array as $key => $row) {
$response[] = (
array(
"id" => $row['code'],
"name" => $row['name']
)
);
I have set 128 mb memory on the server. So if i try to fetch 21mb data it will fails ...