Copy Code code as follows:
$sub _form = Array ();
$loop = 0;
$ins _loop = 0;
$sum = count ($form _datas);
$this->logger->info (' Insert data total: '. $sum);
Using things in bulk imports helps improve insertion efficiency
$callStartTime = Microtime (true);
$this->db->trans_start ();
foreach ($form _datas as $item) {
$loop + +;
$sub _form[] = $item;
if ($loop% = = 0 | | $loop = = $sum) {
$this->logger->info (' Insert data num: '. $loop);
$res = $this->kb_object_instance_mdl->insert_batch ($sub _form, $obj _id);
$ins _loop + +;
unset ($sub _form);
if (($ins _loop% 5) = = 0) {
$this->logger->info (' Insert data trans_complete ins_loop: '. $ins _loop);
$this->db->trans_complete ();
if ($loop!= $sum) {
$this->db->trans_start ();
}
}
}
}
$this->db->trans_complete ();
$callEndTime = Microtime (true);
$callTime = $callEndTime-$callStartTime;
$this->logger->info (' Insert data Use time: '. sprintf ('%.4f ', $callTime));
if ($this->db->trans_status () = = TRUE) {
$this->_show_msg (' 1 ', Array (' Data ' => ' import OK '));
}else{
$this->_show_error (' saveorupdate error ');
}