How can I get the last inserted ID? |
[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.
[eluser]sikkle[/eluser]
wish people still take time to read the user_guide indeed, don't try to go too fast $this->db->insert_id(); This topic has been covered in the forum many many time realy. good luck !
[eluser]EEssam[/eluser]
I swear I searched the user guide but I didn't find that Many thanks.
[eluser]steelaz[/eluser]
Check out this page, it has a few other useful functions http://ellislab.com/codeigniter/user-gui...lpers.html
[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.
[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!
[eluser]Derek Allard[/eluser]
Ah, ok then, no prob, and glad you got it fixed up!
[eluser]sikkle[/eluser]
ya ya it's ok, nothing to be rude, but always type something, do 2-3 search you gonna be surprise good luck and welcome to ci !
[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. |
Welcome Guest, Not a member yet? Register Sign In |