codeigniter使用技巧批量插入數(shù)據(jù)實例方法分享
更新時間:2013年12月31日 09:16:23 作者:
CI批量插入數(shù)據(jù),CodeIgniter是一個小巧但功能強(qiáng)大的 PHP 框架,作為一個簡單而“優(yōu)雅”的工具包,它可以為 PHP 程序員建立功能完善的 Web 應(yīng)用程序
復(fù)制代碼 代碼如下:
$sub_form = array();
$loop = 0;
$ins_loop = 0;
$sum = count($form_datas);
$this->logger->info('insert data total:'.$sum);
//使用事物批量導(dǎo)入有助于提高插入效率
$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');
}
相關(guān)文章
Yii框架獲取當(dāng)前controlle和action對應(yīng)id的方法
這篇文章主要介紹了Yii框架獲取當(dāng)前controlle和action對應(yīng)id的方法,可實現(xiàn)獲取當(dāng)前controlle或action對應(yīng)id的功能,是非常實用的技巧,需要的朋友可以參考下2014-12-12PHP實現(xiàn)數(shù)據(jù)庫的增刪查改功能及完整代碼
這篇文章主要介紹了PHP實現(xiàn)數(shù)據(jù)庫的增刪查改功能及完整代碼,需要的朋友可以參考下2018-04-04PHP 面向?qū)ο蟪绦蛟O(shè)計之類屬性與類常量實現(xiàn)方法分析
這篇文章主要介紹了PHP 面向?qū)ο蟪绦蛟O(shè)計之類屬性與類常量實現(xiàn)方法,結(jié)合實例形式分析了PHP 面向?qū)ο蟪绦蛟O(shè)計中類屬性與類常量的具體功能、原理、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下2020-04-04