codeigniter框架批量插入數(shù)據(jù)
更新時間:2014年01月09日 12:06:17 作者:
本文介紹codeigniter框架批量插入數(shù)據(jù)的實例,優(yōu)化了其中的插入算法,大家參考使用吧
復制代碼 代碼如下:
$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');
}
相關文章
基于PHP Web開發(fā)MVC框架的Smarty使用說明
本篇文章小編為大家介紹,基于PHP Web開發(fā)MVC框架的Smarty使用說明。需要的朋友參考下2013-04-04修改Laravel自帶的認證系統(tǒng)的User類的命名空間的步驟
今天小編就為大家分享一篇修改Laravel自帶的認證系統(tǒng)的User類的命名空間的步驟,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10