codeigniter使用技巧批量插入數(shù)據(jù)實(shí)例方法分享
更新時(shí)間:2013年12月31日 09:16:23 作者:
CI批量插入數(shù)據(jù),CodeIgniter是一個(gè)小巧但功能強(qiáng)大的 PHP 框架,作為一個(gè)簡單而“優(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)文章
實(shí)例分析PHP將字符串轉(zhuǎn)換成數(shù)字的方法
在本篇文章里我們給大家分享的是關(guān)于PHP將字符串轉(zhuǎn)換成數(shù)字的方法和相關(guān)知識(shí)點(diǎn),有興趣的朋友們學(xué)習(xí)下。2019-01-01
thinkPHP5.0框架自動(dòng)加載機(jī)制分析
這篇文章主要介紹了thinkPHP5.0框架自動(dòng)加載機(jī)制,較為詳細(xì)的分析了thinkPHP5.0自動(dòng)加載的概念、原理、用法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-03-03
PHP讀取CSV大文件導(dǎo)入數(shù)據(jù)庫的實(shí)例
下面小編就為大家?guī)硪黄狿HP讀取CSV大文件導(dǎo)入數(shù)據(jù)庫的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
php使用event擴(kuò)展的io復(fù)用測(cè)試的示例
這篇文章主要介紹了php使用event擴(kuò)展的io復(fù)用測(cè)試的示例,幫助大家更好的理解和使用php,感興趣的朋友可以了解下2020-10-10
php layui實(shí)現(xiàn)前端多圖上傳實(shí)例
在本篇文章里小編給大家整理的是關(guān)于php結(jié)合layui前端實(shí)現(xiàn)多圖上傳的實(shí)例內(nèi)容,有需要的朋友們可以參考下。2019-07-07
php根據(jù)isbn書號(hào)查詢amazon網(wǎng)站上的圖書信息的示例
這篇文章主要介紹了php根據(jù)isbn書號(hào)查詢amazon網(wǎng)站上的圖書信息的示例,需要的朋友可以參考下2014-02-02

