php - Fetching a json_encoded array exhausts memory -
i have 2 arrays form inputs trying combine , store in single database cell. able this, when trying retrieve it, gives fatal error of exhausting memory limit.
i inserting main slider has additional slides within it. kind of. don't want create individual sql tables, maybe need to.
my memory @ 256mb, know increase more i'd rather figure out why large.
so inputs coming from:
<fieldset class="form-group"> <label class="label-top" for="scroll-content[]">scroll text #1</label> <textarea rows="5" cols="50" name="scroll-content[]" id="scroll-content-"></textarea> <input type="hidden" name="slide-number[]" value="1"> </fieldset> <fieldset class="form-group"> <label class="label-top" for="scroll-content[]">scroll text #2:</label> <textarea rows="5" cols="50" name="scroll-content[]" id="scroll-content-"></textarea> <input type="hidden" name="slide-number[]" value="2"> </fieldset>
inserting:
function add_new_scroll($dir, $plugin_id) { // configure content array $num = $_post['slide-number']; $array = $_post['scroll-content']; $combined = array_combine($num, $array); $content = json_encode($combined); // global connection global $conn; wj_connect(); // sql $sql = "insert `scroll_text` (`scroll_order`, `num_slides`, `scroll_title`, `scroll_slug`, `scroll_content`) values(?,?,?,?,?) on duplicate key update `scroll_order` = values(`scroll_order`), `num_slides` = values(`num_slides`), `scroll_title` = values(`scroll_title`), `scroll_slug` = values(`scroll_slug`), `scroll_content` = values(`scroll_content`)"; if ($stmt = $conn->prepare($sql)) { $stmt->bind_param("iisss", $ansp_order, $ansp_num_slides, $ansp_title, $ansp_slug, $ansp_content); // set params $ansp_order = 0; $ansp_num_slides = 1; $ansp_title = $_post['scroll-title']; $ansp_slug = $_post['scroll-slug']; $ansp_content = $content; $stmt->execute(); $stmt->close(); } else { echo 'scroll text not added.'; } $conn->close(); header("location: ". $dir . "/scroll-text-admin.php?plug_id=" . $plugin_id . "&type=edit&slug=" . $ansp_slug); }
stores like:
{"1":"<p>1<\/p>","2":"<p>2<\/p>"}
retrieving:
function return_scroll() { // global connection global $conn; wj_connect(); // sql $sql = "select `id`, `scroll_order`, `num_slides`, `scroll_title`, `scroll_slug`, `scroll_content` `scroll_text` `scroll_slug` = ? limit 1"; if ($stmt = $conn->prepare($sql)) { $stmt->bind_param("s", $rsp_slug); $rsp_slug = $_get['slug']; $stmt->execute(); // bind results $stmt->bind_result($rsr_id, $rsr_order, $rsr_num_slides, $rsr_title, $rsr_slug, $rsr_content); $scroll = array( 'id' => $rsr_id, 'order' => $rsr_order, 'num_slides' => $rsr_num_slides, 'title' => $rsr_title, 'slug' => $rsr_slug, 'content' => $rsr_content ); $stmt->fetch(); $stmt->close(); } $conn->close(); return $scroll; }
error!:
fatal error: allowed memory size of 268435456 bytes exhausted (tried allocate 4294967296 bytes) in /home/wonderadmin/public_html/wj-admin/plugins/scroll-text/scroll-text.php on line 199
well mysql database row type longtext. changed mediumtext , i'm fine. embarrassing.
Comments
Post a Comment