php - Memory size exhaused while putting data into array -


i'm trying data database , store json file. script below works fine, larger datatables not work:

# select data table $query = "select `row1`,                   `row2`,                   `row3`             `table`"; $result = $mysqli->query( $query );  # declare array  $data = array();  # put data array while ( $row = $result->fetch_assoc() ) {   $data[] = $row; }  # put data json $jsondata = json_encode( $data, json_pretty_print ); 

but larger tables won't work: fatal error: allowed memory size of 104857600 bytes exhausted.

the error occours in segment "put data array" (see code above).

are there other ways data json?

further mark baker's response here's temporary solution streaming json:

# select data table $query = "select `row1`,               `row2`,               `row3`         `table`"; $result = $mysqli->query( $query );  header("content-type: application/json"); echo "["; # put data array $first = true; while ( $row = $result->fetch_assoc() ) {       echo (!$first?",":"").json_encode($row);       $first = false; } echo "]"; die(); 

now here's catch. cannot put data in array or string, can transmit it. in addition, if you're using output buffering (with ob_start) still run out of memory.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -