Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Get last insert id?

edited October 2011 in Modules
I am using the insert method:


on an table with id as the autoincrement primary key.

How can I retrieve the new id that was inserted? Equivalent to PHP's mysql_insert_id() function.

Thanks in advance.


  • edited 8:08PM
    CodeIgniter has a $this->db->insert_id() method. In your case you could do the following:
    Alternatively, if you use MY_Model's "save" method instead, it will automatically return the insert_id:
    $id = $this->examples_model->save($values);
  • edited 8:08PM
    Great! Thanks. save() looks like the better option.
Sign In or Register to comment.