tags:

views:

910

answers:

1

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.

+2  A: 

Shame on me...

I looked at http://codeigniter.com/user_guide/database/helpers.html and the first function is $this->db->insert_id();

This also works with activerecord inserts...

Dennis Decoene
the userguide is your best friend for things like this. i have been using codeigniter for 2+ years and i still find functions like this that i never knew about.
Tom Schlick