Pages

Saturday, June 30, 2018

Codeigniter | How to Insert Batch Records

When you want to insert batch data into database table then you not need to insert using loop just use insert_batch function provided by Codeigniter.
Example :

$data = array(
   array(
      'title' => 'Title 1' ,
      'name' => 'Name 1' ,
      'date' => 'date('Y-m-d H:i:s)'
   ),
   array(
      'title' => 'Title 2' ,
      'name' => 'Name 2' ,
      'date' => 'date('Y-m-d H:i:s)'
   )
);

$this->db->insert_batch('your_table_name', $data);

This will reduce memory and execution time. 

No comments:

Post a Comment