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 1:59AM
    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 1:59AM
    Great! Thanks. save() looks like the better option.
Sign In or Register to comment.