Database identity after an insert (probably a newbie question) |
[eluser]Antonio Fernández[/eluser]
Hi! Usually when I was coding in raw php I was used to make something like this: Code: mysql_query("INSERT INTO `my_table` (a,b) VALUES ('aa','bb'); getting the last id inserted on the table. Are there something similar on CI? Code: $data = array( This also works but I'm wondering if there is something like ... Code: $id = $this->db->insert_id(); ... so you can be sure that you are getting the same id in the transaction. Thanks a lot in advance.
[eluser]Isern Palaus[/eluser]
[quote author="fernandezvara" date="1269979934"]This also works but I'm wondering if there is something like ... Code: $id = $this->db->insert_id(); ... so you can be sure that you are getting the same id in the transaction.[/quote] Hello fernandezvara, You're right, $this->db->insert_id(); exists! Check the userguide Query Helper Functions: $this->db->insert_id() The insert ID number when performing database inserts. Regards, Isern
[eluser]Antonio Fernández[/eluser]
[quote author="Isern Palaus" date="1269980338"][quote author="fernandezvara" date="1269979934"]This also works but I'm wondering if there is something like ... Code: $id = $this->db->insert_id(); ... so you can be sure that you are getting the same id in the transaction.[/quote] Hello fernandezvara, You're right, $this->db->insert_id(); exists! Check the userguide Query Helper Functions: $this->db->insert_id() The insert ID number when performing database inserts. Regards, Isern[/quote] Omg, I have tryed something like $this->db->insertid() :down:, and haven't found that option on the documentation. Thanks a lot Isern. |
Welcome Guest, Not a member yet? Register Sign In |