CodeIgniter activerecord, retrieve last insert id? CodeIgniter activerecord, retrieve last insert id? codeigniter codeigniter

CodeIgniter activerecord, retrieve last insert id?


Shame on me...

I looked at the user guide and the first function is $this->db->insert_id();

This also works with activerecord inserts...

EDIT: I updated the link


Last insert id means you can get inserted auto increment id by using this method in active record,

$this->db->insert_id() // it can be return insert id it is // similar to the mysql_insert_id in core PHP

You can refer this link you can find some more stuff.

Information from executing a query


for Specific table you cannot use $this->db->insert_id() . even the last insert happened long ago it can be fetched like this. may be wrong. but working well for me

     $this->db->select_max('{primary key}');     $result= $this->db->get('{table}')->row_array();     echo $result['{primary key}'];