Welcome Guest, Not a member yet? Register   Sign In
Selecting the record I've just inserted?

I'm using active records in CI to insert records.

In one table, the ID is a primary key set to auto-increment, so I just leave it empty while inserting and the database will assign an ID number for it.

However, I have to use that same ID to insert a record into a related table right after that.

My question is, how do I select the ID of the record I've just inserted?

Thanks in advance!

you can use $this->db->insert_id().

Thanks xwero. Works perfectly now. Smile

Pretty cool this information, I will use it in my next app Smile

Hi !

I update this topic just to know if someone can put there a little piece of code with the function Insert_id() because I have to use it but I don't really know how ...

Thanks in advance =)

return $this->db->insert_id();

Thanks a lot !

It's totally what I was looking for !

Thank you !

Theme © iAndrew 2016 - Forum software by © MyBB