Mysql can perform multiple updates or inserts. Usually in the Active Record template you insert one after the other, but for mass updates or attachments you can do this.
$sql = "INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12) ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2);";
$this->db->query($sql);
source
share