CodeIgniter 3.0 insert_batch works localhost but not on server

妖精的绣舞 提交于 2019-12-24 06:40:52

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/41475400/codeigniter-3-0-insert-batch-works-localhost-but-not-on-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!