我的目标是使用 CodeIgniter 的组合insert_batch()并将update_batch()传入数据添加到我的macro_plan表中。
在我下面的脚本中,我试图根据sr_no值查询数据库中的现有行,然后适当地调用批量查询方法。
function insert_batch($dataSet)
{
$query = $this->db->query("select sr_no from macro_plan");
$data = $query->result_array();
$sr_nos=array();
foreach($data as $key => $value):
$sr_nos[$key]=$value['sr_no'];
endforeach;
$query1= $this->db->query("select * from macro_plan WHERE sr_no IN ('".$sr_nos."')");
$update_query = $query1->result();
if ($update_query->num_rows() > 0) {
$this->db->update_batch($dataSet,$this->macro_plan);//update if ids exist
} else {
$this->db->insert_batch($dataSet,$this->macro_plan);//insert if does not exist
}
}
但是,我收到“数组到字符串转换”错误。
$dataset将类似于:
Array (
[0] => Array (
[quantity_update] => 88
[sr_no] => 2020-11-1
[batch] => Batch 2
[quantity_date_update] => 05-May-20
[inq_id] => 49
)
[1] => Array (
[quantity_update] => 99
[sr_no] => 2020-11-2
[batch] => Batch 1
[quantity_date_update] => 11-May-20
[inq_id] => 49
)
)
我的表结构如下所示:
慕丝7291255