doulu7174 2017-08-20 03:35
浏览 48

获取json编码的数组会耗尽内存

I have two arrays from form inputs that I am trying to combine and store in a single database cell. I am able to do this, but when trying to retrieve it, it gives a fatal error of exhausting the memory limit.

I am inserting a main slider basically that has additional slides within it. Kind of. I don't want to create individual sql tables, but maybe I need to.

My memory is at 256mb, I know I could increase it more but I'd rather figure out why it is so large.

So my Inputs are 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 INTO `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`
                FROM `scroll_text` WHERE `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 to allocate 4294967296 bytes) in /home/wonderadmin/public_html/wj-admin/plugins/scroll-text/scroll-text.php on line 199
  • 写回答

1条回答 默认 最新

  • dongpengyu1363 2017-08-20 04:03
    关注

    Well my MySQL database row type was longtext. Changed it to mediumtext and I'm fine. Embarrassing.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?