CodeIgniter activerecord, retrieve last insert id?
Asked 07 September, 2021
Viewed 2K times
  • 51
Votes

Are there any options to get the last insert id of a new record in CodeIgniter?

$last_id = $this->db->insert('tablename',
    array('firstcolumn' => 'value',
    'secondcolumn' => 'value')
);

Considering the table consits of fields id (autoincrement) firstcolumn and secondcolumn.

This way you can use the insert id in the following code.

11 Answer