codeigniter使用技巧批量插入數(shù)據(jù)實(shí)例方法分享
更新時(shí)間:2013年12月31日 09:16:23 作者:
CI批量插入數(shù)據(jù),CodeIgniter是一個(gè)小巧但功能強(qiáng)大的 PHP 框架,作為一個(gè)簡(jiǎn)單而“優(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對(duì)應(yīng)id的方法
這篇文章主要介紹了Yii框架獲取當(dāng)前controlle和action對(duì)應(yīng)id的方法,可實(shí)現(xiàn)獲取當(dāng)前controlle或action對(duì)應(yīng)id的功能,是非常實(shí)用的技巧,需要的朋友可以參考下2014-12-12PHP簡(jiǎn)單的MVC框架實(shí)現(xiàn)方法
在PHP中使用MVC越來越流行了,特別是在一些開源的框架當(dāng)中。本篇給大家介紹php簡(jiǎn)單的mvc框架實(shí)現(xiàn)方法,對(duì)php簡(jiǎn)單的mvc框架相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2015-12-12一個(gè)簡(jiǎn)單安全的PHP驗(yàn)證碼類、PHP驗(yàn)證碼
這篇文章主要介紹了一個(gè)簡(jiǎn)單安全的PHP驗(yàn)證碼類 PHP驗(yàn)證碼的相關(guān)資料,需要的朋友可以參考下2016-09-09PHP實(shí)現(xiàn)數(shù)據(jù)庫(kù)的增刪查改功能及完整代碼
這篇文章主要介紹了PHP實(shí)現(xiàn)數(shù)據(jù)庫(kù)的增刪查改功能及完整代碼,需要的朋友可以參考下2018-04-04PHP 面向?qū)ο蟪绦蛟O(shè)計(jì)之類屬性與類常量實(shí)現(xiàn)方法分析
這篇文章主要介紹了PHP 面向?qū)ο蟪绦蛟O(shè)計(jì)之類屬性與類常量實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了PHP 面向?qū)ο蟪绦蛟O(shè)計(jì)中類屬性與類常量的具體功能、原理、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下2020-04-04