代码如下:
$sub_form = array();
$loop = 0;
$ins_loop = 0;
$sum = count($form_datas);
$this->logger->info('insert data total:'.$sum);
//使用事物批量导入有助于提高插入效率
$callStartTime = microtime(true);
$this->db->trans_start();
foreach ( $form_datas as $item ) {
$loop ++;
$sub_form[] = $item;
if(($loop % 200) == 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');
}
$loop = 0;
$ins_loop = 0;
$sum = count($form_datas);
$this->logger->info('insert data total:'.$sum);
//使用事物批量导入有助于提高插入效率
$callStartTime = microtime(true);
$this->db->trans_start();
foreach ( $form_datas as $item ) {
$loop ++;
$sub_form[] = $item;
if(($loop % 200) == 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');
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。