Welcome Guest, Not a member yet? Register   Sign In
ID of last database object inserted.
#1

[eluser]wdcmatt[/eluser]
I've been surfing around the user guide and searching in the forums, and I just wanted to know is there a function/method/class/helper...etc. that can tell me the ID (primary key) of the last item inserted?

Obviously I could write custom code to do so, but I was hoping there was already a function that did this built into the framework. I am just trying to insert an entry and then pass the ID to another function that performs post insert processes.

Thanks in advance.
#2

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...lpers.html

$this->db->insert_id()
#3

[eluser]wdcmatt[/eluser]
Thank you much, I spent about 10 minutes surfing through there and didn't see that.
#4

[eluser]Wayne Smallman[/eluser]
[quote author="noctrum" date="1276884496"]http://ellislab.com/codeigniter/user-gui...lpers.html

$this->db->insert_id()[/quote]Noctrum, I have a question regarding this function, because the Query Helper page is very thin on information.

"The insert ID number when performing database inserts."

Potentially, this could mean the last insert by anyone. So would this be "my" ID or someone else's?
#5

[eluser]CroNiX[/eluser]
Yours. It may be other people are querying the db, but not on your mysql link resource id.
#6

[eluser]Wayne Smallman[/eluser]
[quote author="CroNiX" date="1284278968"]Yours. It may be other people are querying the db, but not on your mysql link resource id.[/quote]CroNIX, thanks for the feedback!

Your reply links in with similar discussions elsewhere, so you may have killed several birds with a single stone...




Theme © iAndrew 2016 - Forum software by © MyBB