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 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致