Copy code The code is as follows:
$sub_form = array();
$loop = 0;
$ins_loop = 0;
$sum = count($form_datas);
$this->logger->info('insert data total:'.$sum);
//Use transaction batch Importing helps improve insertion efficiency
$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){
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');
}
http://www.bkjia.com/PHPjc/633585.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633585.htmlTechArticleCopy the code as follows: $sub_form = array(); $loop = 0; $ins_loop = 0; $sum = count($form_datas); $this-logger-info('insert data total:'.$sum); //Using transaction batch import helps...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn