dqq3623 2017-01-05 00:22
浏览 27
已采纳

CodeIgniter 3.0 insert_batch适用于localhost,但不适用于服务器

I have a customer model with the following function:

public function add($data)
{
    $this->db->insert_batch('customers', $data);
}

Using this function in localhost on a 5.6 php environment works without any problem. On server with 7.0 php environment I receive the error:

<p>Severity: Warning</p>
<p>Message:  array_keys() expects parameter 1 to be array, boolean given</p>
<p>Filename: database/DB_query_builder.php</p>
<p>Line Number: 1549</p>

<h1>A Database Error Occurred</h1>
<p>Error Number: 1136</p><p>Column count doesn't match value count at row 1</p><p>INSERT INTO `customers` () VALUES ('John Doe', '25', 'Male'), ('Brad Doe', '22', 'Male')</p><p>Filename: models/Customers_model.php</p><p>Line Number: 22</p>

Well, I dunno why the final query has no column names, since my $data content is perfect.

public function add($data)
{
    print_r($data);
    $this->db->insert_batch('customers', $data);
}

The output:

Array
(
    [0] => Array
        (
            [name] => 'John Doe'
            [age] => 25
            [sex] => 'Male'
        )

    [1] => Array
        (
            [name] => 'Brad Doe'
            [age] => 22
            [sex] => 'Male'
        )
)

And finally my server configuration on Cpanel enter image description here

  • 写回答

1条回答 默认 最新

  • dongyi6845 2017-01-05 03:09
    关注

    I think I found the culprit. It happened to me when I was testing on PHP 7.0.0 (for some reason) as well today:

    bcit-ci/CodeIgniter Issue #4804: error insert_batch using PHP7

    Looks like the maintainer used reset() instead of the original current() to grab the first element. This Snippet is an example a contributor provided to show the difference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么