In this paper, we introduce the example of CodeIgniter frame in batch inserting data, and optimize the inserting algorithm, we refer to the use of the bar
Code as follows: $sub _form = Array (); $loop = 0; $ins _loop = 0; $sum = count ($form _datas); $this->logger->info (' Insert data total: '. $sum); //Use of things bulk import helps improve insertion efficiency $callStartTime = Microtime (true); $this->db->trans_start (); foreach ($form _datas as $item) { $loop + + $s Ub_form[] = $item; if ($loop%) = = 0 | | $loop = $sum) { $this->lo Gger->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 '); &NBSP}