CodeIgniter Forums
MySQL Insert ID? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MySQL Insert ID? (/showthread.php?tid=17739)



MySQL Insert ID? - El Forum - 04-14-2009

[eluser]Tim Stackhouse[/eluser]
I'm such a newb... Anyway, I've poured over the User Guide and the Wiki and I can't figure out how to get the last inserted id. Here's the scenario:

I have 2 classes and corresponding tables: User and Person. User has a foreign key constraint that references person, which may or may not already have a record for a person trying to register. I've got this part taken care of. However When it comes time to save their info, I'll need to know the id of the person object I created if one didn't already exist, so what do I call to get that?


MySQL Insert ID? - El Forum - 04-14-2009

[eluser]NogDog[/eluser]
$this->db->insert_id()


MySQL Insert ID? - El Forum - 04-14-2009

[eluser]Tim Stackhouse[/eluser]
Thanks. I was looking in the wrong spot. I feel like an idiot now Big Grin