codeigniter使用技巧批量插入数据实例方法分享
2013-12-31 09:16
711 查看
$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'); }
相关文章推荐
- codeigniter使用技巧批量插入数据实例方法分享
- codeigniter使用技巧批量插入数据实例方法分享
- 批量删除wps文档里的回车符的方法!WPS使用技巧分享!
- C#使用DataAdapter.Update(dt)方法,无法批量插入数据的原因及解决
- Vivado使用的经验和技巧分享——Vivado中数据导入MATLAB的方法
- ThinkPHP3.2框架使用addAll()批量插入数据的方法
- ThinkPHP3.2使用addAll()方法批量插入数据
- 使用JDBC在MySQL数据库中快速批量插入数据
- Mysql游标使用 批量插入或更新数据
- 超实用Word技巧分享!这才是使用Word时常用到的高效率方法
- POI读取excel2007文件的数据,插入数据库的使用方法【经验之谈】
- python使用MySQLdb向mySQL批量插入数据的方法
- ASP.NET使用Command对象向数据库批量插入记录(十条)
- 【批量生成10万条sql数据库数据+IO流的使用】生成简单sql插入语句大量数据,以及输出流生成文件2017年
- Redis基本使用及百亿数据量中的使用技巧分享
- 使用JdbcTemplate 向ORACLE插入大文本CLOB数据的方法
- 使用事务操作SQLite数据批量插入
- 使用JDBC在MySQL数据库中如何快速批量插入数据
- 批量插入数据 C# SqlBulkCopy使用
- 批量插入数据 C# SqlBulkCopy使用