How to the fetch id of newly created entry |
[eluser]Unknown[/eluser]
Hi there. I am new to using CodeIgniter but am really enjoying it's features. Can anyone please tell me how I can fetch the id of a newly inserted database entry? I am basically looking for a return similar to what I would get if I used Code: mysql_lastid I am currently inserting by doing: Code: $this->db->insert('tablename') But haven't been able to figure out from the documentation how I get the id back. Thanks! Ivar
[eluser]Developer13[/eluser]
http://ellislab.com/codeigniter/user-gui...lpers.html
[eluser]pointer[/eluser]
Code: $this->db->limit(1); Code: $data['query']=$this->db->query("SELECT id FROM table ORDER BY id DESC LIMIT 1");
[eluser]Developer13[/eluser]
pointer, that is the long and inefficient way to do it. Just follow the link to the database helpers -- simply calling $this->db->insert_id() after performing an insert will find the inserted id.
[eluser]manilodisan[/eluser]
Or: Code: $this->db->call_function ('insert_id');
[eluser]ray73864[/eluser]
ooooh, sooo complicated in all the ways. try this: $this->db->insert_id() ahh, D13 already said that earlier, should have read first.
[eluser]Colin Williams[/eluser]
Or: Code: $first = 'InsErt_'; |
Welcome Guest, Not a member yet? Register Sign In |