Welcome Guest, Not a member yet? Register   Sign In
How can I get the last inserted ID?
#1

[eluser]EEssam[/eluser]
Hello,

I need to insert a row then get the primary key of the just inserted row so I can use it to insert more related rows in another table.

Please help. Thanks.
#2

[eluser]sikkle[/eluser]
wish people still take time to read the user_guide indeed, don't try to go too fast Smile

$this->db->insert_id();

This topic has been covered in the forum many many time realy.

good luck !
#3

[eluser]EEssam[/eluser]
I swear I searched the user guide but I didn't find that Sad

Many thanks.
#4

[eluser]steelaz[/eluser]
Check out this page, it has a few other useful functions http://ellislab.com/codeigniter/user-gui...lpers.html
#5

[eluser]Derek Allard[/eluser]
Hey, no problem, we've all missed things before. In order for me to help make the userguide more search friendly, what did you search for? When I search for "How can I get the last inserted ID?" or "get the last inserted ID?" it comes right up.
#6

[eluser]EEssam[/eluser]
Hi Derek,

I actually didn't type any keywords. I was looking for it in ActiveRecord section, I thought I may find it in the 'select' part!
#7

[eluser]Derek Allard[/eluser]
Ah, ok then, no prob, and glad you got it fixed up! Wink
#8

[eluser]sikkle[/eluser]
ya ya it's ok, nothing to be rude, but always type something, do 2-3 search you gonna be surprise Smile

good luck and welcome to ci !
#9

[eluser]Rahul gamit[/eluser]
i am using storedprocedure for inserting the data into the database, and when i am using for $this->db->insert_id()for retrieving the id then it gives me 0.
so how to retrieve last insert id.




Theme © iAndrew 2016 - Forum software by © MyBB