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

[eluser]KeyStroke[/eluser]
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!
#2

[eluser]xwero[/eluser]
you can use $this->db->insert_id().
#3

[eluser]KeyStroke[/eluser]
Thanks xwero. Works perfectly now. Smile
#4

[eluser]Rubiz'[/eluser]
Pretty cool this information, I will use it in my next app Smile
#5

[eluser]BonnyBoboll[/eluser]
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 =)
#6

[eluser]xwero[/eluser]
Code:
$this->db->set('field',$value)->insert();
return $this->db->insert_id();
#7

[eluser]BonnyBoboll[/eluser]
Thanks a lot !

It's totally what I was looking for !

Thank you !




Theme © iAndrew 2016 - Forum software by © MyBB