CodeIgniter Frame BULK INSERT Data

Source: Internet
Author: User
Tags bulk insert codeigniter

  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}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.