Quantcast
Channel: mysql – blog.azwan.net
Viewing all articles
Browse latest Browse all 17

Codeigniter bulk insert to database

$
0
0

If you are to insert hundreds or thousands of records, please use bulk insert. Avoid call insert query in loop.

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name' ,
      'date' => 'My date'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name' ,
      'date' => 'Another date'
   )
);

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

There will be limit to how many records can be added at one go.

Some limitations

  1. Limit to 1000 records per insert statement
  2. Check the settings for max_allowed_packet, bulk_insert_buffer_size, key_buffer_size

Viewing all articles
Browse latest Browse all 17

Trending Articles