You are probably encoding a very large data set. You can encode each line, one line at a time, rather than encode it in one big operation.
<?php require('../../admin/db_login.php'); $db=mysql_connect($host, $username, $password) or die('Could not connect'); mysql_select_db($db_name, $db) or die(''); $result = mysql_query("SELECT * from listinfo") or die('Could not query'); if(mysql_num_rows($result)){ echo '{"testData":['; $first = true; $row=mysql_fetch_assoc($result); while($row=mysql_fetch_row($result)){ // cast results to specific data types if($first) { $first = false; } else { echo ','; } echo json_encode($row); } echo ']}'; } else { echo '[]'; } mysql_close($db);
Thus, each json_encode() call encodes only a small array, not a large one. The end result is the same. This is an IMO solution that will use less memory.
Andrew Moore
source share