Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter batch insert performance

Does $this->db->insert_batch(); insert with 1 table connection or does it insert each row separately incurring overhead of opening connections?

like image 265
el_pup_le Avatar asked Dec 26 '11 13:12

el_pup_le


2 Answers

From the documentation of code igniter insert_batch do this kind of things

$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); 

// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')

So it would produce only one query with all the values, normally this way faster then doing separate inserts.

like image 127
RageZ Avatar answered Sep 23 '22 21:09

RageZ


To answer your question: It uses one connection.

like image 28
phirschybar Avatar answered Sep 26 '22 21:09

phirschybar