CodeIgniter: INSERT multiple records without cycle
Codeigniter active record has a function insert_batch
i think that is what you need
$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')
Works for both Codeigniter 3.x and Codeigniter 2.2.6
UPDATED LINKS
for CodeIgniter 4x use $builder->insertBatch()
$data = [ [ 'title' => 'My title', 'name' => 'My Name', 'date' => 'My date' ], [ 'title' => 'Another title', 'name' => 'Another Name', 'date' => 'Another date' ]];$builder->insertBatch($data);// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')