Codeigniter insert_batch 限制问题

Codeigniter insert_batch limitation issue

我正在使用 codeigniter insert_batch() 函数,而不是通过简单的插入来循环数据。我的行数约为 390,其中只有 100 行插入,因为 codeigniter(或 mysql)不允许在单个查询中插入超过 100 行。

然后我用 array_chunk 函数将 100 除以 100,如下所示:

$all_hafars = array_chunk($hafar_co,100);
foreach ($all_hafars as $hafar) {
    $this->db->insert_batch('hafar_co', $hafar);
}

再次只有 100 个插入!有什么想法吗?

编辑: 我什至将简单的 insert 函数与 transaction 一起使用。当我使用事务时,它再次只插入 100 行。

insert_batch Is going to prevent some mysql limit problems. I think that it's related to configuration in your MySQL. The main idea is to avoid if you try to cross something.

我建议你使用事务而不是 insert_batch。

您可以在此处阅读有关交易的更多信息:https://www.codeigniter.com/user_guide/database/transactions.html

您可以在此处详细了解您的问题:https://github.com/bcit-ci/CodeIgniter/issues/2680

PHP 的查询受限于 max_allowed_packet 配置选项。它定义了查询字符串的绝对长度限制(以字符为单位)。请注意,这不仅仅是要插入的数据的总大小,而是整个查询字符串。 SQL 命令、标点符号、空格等...

SHOW VARIABLES WHERE Variable_name LIKE  '%max_allowed_packet%'