简体   繁体   English

获取json_encoded数组会耗尽内存

[英]Fetching a json_encoded array exhausts memory

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. 我不想创建单独的sql表,但是也许我需要。

My memory is at 256mb, I know I could increase it more but I'd rather figure out why it is so large. 我的内存为256mb,我知道我可以增加更多,但我想弄清楚为什么它这么大。

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

Well my MySQL database row type was longtext. 我的MySQL数据库行类型是longtext。 Changed it to mediumtext and I'm fine. 更改为中文字,我很好。 Embarrassing. 不好意思

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM