Mysql Codeigniter-插入批处理-我的sql

Mysql Codeigniter-插入批处理-我的sql,mysql,codeigniter,Mysql,Codeigniter,// 严重性:通知 Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Array' at line 1 请做些改变 Message: Trying to get property of non-object Filena

// 严重性:通知

  Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to      your MySQL server version for the right syntax to use near 'Array' at line 1

请做些改变

 Message: Trying to get property of non-object

Filename: models/productmodel.php

Line Number: 24

  Backtrace:

 File: E:\wamp\www\CodeIgniter\application\models\productmodel.php
 Line: 24
Function: _error_handler
for($i=1;$i<$this->input->post('customer\u numrows');$i++)
{
$data[]=数组(
“产品id”=>$temp,
“范围”=>0,
“增值税”=>0,
“价格”=>$this->input->post('customer\u amount'.$i),
“计量单位”=>$this->input->post('customer\u uom'.$i),
“usertype”=>$customer
);
}
$this->db->insert_batch('product_pricing',$data);
}  

当您使用
$this->db->insert_batch('product_pricing',$data)
时,对于
$data
中的所有值,它必须是其键必须相同的数组。

此错误的特殊之处在于:

您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“Array”附近使用的语法是否正确

for ($i = 1; $i < $this->input->post( 'customer_numrows' ); $i++)
{

 $data[] = array(
          'product_id' => $temp,
          'range'       => 0,
          'vat@'       => 0,
          'price'       => $this->input->post( 'customer_amount' . $i ),
          'uom'      => $this->input->post( 'customer_uom' . $i ),
          'usertype' => $customer
           );
}
 $this->db->insert_batch( 'product_pricing', $data );
}  
这意味着,
,数组
实际上被放入查询中。。。我知道这没有多大意义,但我认为这是一个CodeIgniter错误,原因如下:

  • 在调用
    my_table
    insert_batch
    之前,我有多个
    insert_batch
    调用其他表
    它们都工作得很好
  • my_表
    的列数比以前所有获得
    insert_批处理的表
    的列数多得多
  • 调用参数(每行仅1列)数组中的
    my_table
    insert_batch
    时,仅使用非null
    ['column_name'=>'value']
    。。。因此,表结构的参数数量/类型似乎正在影响此方法的功能
  • 因此,为了确认这是一个CodeIgniter问题/bug(某种程度上与表的结构和
    insert\u batch
    方法有关),我添加了单独的insert。例如:

    INSERT INTO `my_table` () VALUES (1,2,3), Array
    

    他们使用的列/值对与我提供给
    insert\u batch
    数组的列/值对完全相同。

    似乎你可以使用不使用batch的insert,我应该使用insert吗?!你们有多少?删除循环的所有
    ,并可以使用
    插入批处理
    。同样,
    $data[]
    $data
    一样更改,但我必须在我的表中的“usertype”列中插入第一批的“批发”,第二批的“经销商”,第三批的“客户”使用类似
    $usertype
    $wholesale
    $dealer
    的3 diff数组。。。
    INSERT INTO `my_table` () VALUES (1,2,3), Array
    
    $this->db->insert('my_table', ['col1' => 'value']);
    $this->db->insert('my_table', ['col1' => 'value', 'col2' => 'value']);