Codeigniter insert_batch失败奇怪的数组变成字符串

时间:2018-11-14 09:44:22

标签: codeigniter

所以现在我传递一个json,这是echo '<pre>' . var_export($data, true) . '</pre>';的结果:

    array (
      0 => 
      array (
        'booking_id' => 99,
        'item_type' => '67',
        'sales_item_seq' => '1',
        'package_item_id' => '0',
        'package_item_seq' => '0',
        'package_group' => '0',
        'package_group_rowspan' => '0',
        'package_group_subdata_rowspan' => '0',
        'channel_id' => '380',
        'name_of_channel_programme' => '123',
        'schedule_from' => '0000-00-00 00:00:00',
        'schedule_to' => '0000-00-00 23:59:59',
        'no_of_unit' => '123.00',
        'exposure_inside_per_unit' => '',
        'exposure_duration' => '123',
        'advertising_offier' => '0.00',
        'special_discount' => '0',
        'net' => '0.00',
        't_n_c' => '',
        'remark' => '',
        'status' => '1',
        'create_datetime' => '2018-11-14 17:00:33',
        'update_datetime' => '2018-11-14 17:00:33',
        'channel' => '2',
        'package_name' => '',
        'sale_item_name' => 'hello',
        'cat_id' => '1',
        'aftersales_type' => '',
        'typing_guide' => '',
        'position' => '',
        'platform_des' => 'hello',
        'nature_des' => 'hello',
        'unit_des' => 'Account',
      ),
...
...
...
      9 => 
      array (
        'booking_id' => 99,
        'item_type' => '59',
        'sales_item_seq' => '1',
        'package_item_id' => '0',
        'package_item_seq' => '0',
        'package_group' => '0',
        'package_group_rowspan' => '0',
        'package_group_subdata_rowspan' => '0',
        'channel_id' => '0',
        'name_of_channel_programme' => 'N/A',
        'schedule_from' => '0000-00-00 00:00:00',
        'schedule_to' => '0000-00-00 00:00:00',
        'no_of_unit' => '123.00',
        'exposure_inside_per_unit' => 'N/A',
        'exposure_duration' => 'N/A',
        'advertising_offier' => '1000.00',
        'special_discount' => '100',
        'net' => '0.00',
        't_n_c' => '',
        'remark' => '',
        'status' => '1',
        'create_datetime' => '2018-11-14 17:00:33',
        'update_datetime' => '2018-11-14 17:00:33',
        'channel' => '',
        'package_name' => '',
        'sale_item_name' => 'Service Charge',
        'cat_id' => '7',
        'aftersales_type' => '',
        'typing_guide' => 'N/A',
        'position' => 'N/A',
        'platform_des' => 'N/A',
        'nature_des' => 'Operations',
        'unit_des' => 'Campaign',
      ),
      10 => 
      array (
        'booking_id' => 99,
        'item_type' => '0',
        'sales_item_seq' => '0',
        'package_item_id' => '161',
        'package_item_seq' => '0',
        'package_group' => '1',
        'package_group_rowspan' => '6',
        'package_group_subdata_rowspan' => '1',
        'channel_id' => '39',
        'name_of_channel_programme' => 'hello',
        'schedule_from' => '0000-00-00 00:00:00',
        'schedule_to' => '0000-00-00 23:59:59',
        'no_of_unit' => '1.00',
        'exposure_inside_per_unit' => '0',
        'exposure_duration' => '',
        'advertising_offier' => '180000.00',
        'special_discount' => '100',
        'net' => '0.00',
        't_n_c' => '',
        'remark' => '',
        'status' => '1',
        'create_datetime' => '2018-11-14 17:00:33',
        'update_datetime' => '2018-11-14 17:00:33',
        'channel' => 'Catch',
        'package_name' => 'hello',
        'sale_item_name' => 'hello',
        'cat_id' => '1',
        'aftersales_type' => '',
        'typing_guide' => 'Name of Programme',
        'position' => '',
        'platform_des' => 'hello',
        'nature_des' => 'Live',
        'unit_des' => 'Live Segment',
        'package_id' => '28',
      ),
...
...
...
        'unit_des' => 'Video',
        'package_id' => '28',
      ),
    )

当我在在线查看器上查看它时,它看起来不错。在$this->db->insert_batch('table_name',$data)之后,返回错误,指出代码中有Array

  

错误号:1064

     

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本以使用正确的语法   在第1行的“数组”附近

我可以在下面的结尾处找到它(认为这是insert_batch的原始输出):

    INSERT INTO `table_name` () VALUES 
                ( 
                            '0.00', 
                            '', 
                            100, 
                            '1', 
                            '2', 
                            '380', 
                            '2018-11-14 17:06:46', 
                            '123', 
                            '', 
                            '67', 
                            '123', 
                            'Access Right', 
                            '0.00', 
                            '123.00', 
                            '0', 
                            '0', 
                            '0', 
                            '0', 
                            '0', 
                            '', 
                            'hello', 
                            '', 
                            '', 
                            'hello', 
                            '1', 
                            '0000-00-00 00:00:00', 
                            '0000-00-00 23:59:59', 
                            '0', 
                            '1', 
                            '', 
                            '', 
                            'Account', 
                            '2018-11-14 17:06:46' 
                ) 
                , 
...
...
...
                ( 
                            '1000.00', 
                            '', 
                            100, 
                            '7', 
                            '', 
                            '0', 
                            '2018-11-14 17:06:46', 
                            'N/A', 
                            'N/A', 
                            '59', 
                            'N/A', 
                            'Operations', 
                            '0.00', 
                            '123.00', 
                            '0', 
                            '0', 
                            '0', 
                            '0', 
                            '0', 
                            '', 
                            'N/A', 
                            'N/A', 
                            '', 
                            'Service Charge', 
                            '1', 
                            '0000-00-00 00:00:00', 
                            '0000-00-00 00:00:00', 
                            '100', 
                            '1', 
                            '', 
                            'N/A', 
                            'Campaign', 
                            '2018-11-14 17:06:46' 
                ) 
                , 
                array

我不知道为什么从10开始所有元素都变成array。 如果您需要更多信息,请告诉我。谢谢!

1 个答案:

答案 0 :(得分:1)

您的数组索引不匹配。 1-9没有package_id


您可以添加此代码以确保所有数组都具有package_id索引:

array_walk($array, function(&$val){ if (!isset($val['package_id'])) $val['package_id'] = null; });