Codeigniter批量插入性能

el_*_*_le 9 mysql performance codeigniter

是否$this->db->insert_batch();插入1个表连接或是否分别插入每行导致打开连接的开销?

Rag*_*geZ 11

从代码点火器的文档中insert_batch做这种事情

$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')
Run Code Online (Sandbox Code Playgroud)

因此它只生成一个包含所有值的查询,通常这样做比单独插入更快.


phi*_*bar 6

回答你的问题:它使用一个连接.