Is there any way to get last inserted IDs from batch inserts in codeigniter ?
This might seem silly but I wonder if there is any help available.
Is there any way to get last inserted IDs from batch inserts in codeigniter ?
This might seem silly but I wonder if there is any help available.
You're gonna need to run the inserts in a loop, that's the only way to get each of the IDs. To lessen the strain on the server, you can do this inside of a transaction.
$ids = array();
$this->db->trans_start();
foreach($data as $val){
$this->db->insert('yourTable', array(
'field1' => $val['foo'],
'field2' => $val['bar']
));
$ids[] = $this->db->insert_id();
}
$this->db->trans_complete();