• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get the last inserted ID?


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.

wish people still take time to read the user_guide indeed, don't try to go too fast Smile


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

good luck !

I swear I searched the user guide but I didn't find that Sad

Many thanks.

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.

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! Wink

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 !

[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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.