Function $this->db->insert_id() to get last inserted record id always returns 1 - 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: Function $this->db->insert_id() to get last inserted record id always returns 1 (/showthread.php?tid=60582) |
Function $this->db->insert_id() to get last inserted record id always returns 1 - El Forum - 05-01-2014 [eluser]Andy UK[/eluser] Hi, I'm developing a ticket system where tickets are assigned to relationships with clients. If a relationship exists, then the ticket is given that relationship id. If no current relationship exists then a new one is added and the new id is assigned to the ticket that triggered its creation. The problem i have is that when i get the last insert id of the new relationship and add it to the recently created ticket, i'm always getting the value of 1. Here is the controller code... Code: //Insert new ticket into system And here is the relevant model code... Code: function addNewTicket($data) Code: function openNewRelationship($data) $new_relationship_id is the variable that holds the last inserted client relationship and that's the one that is coming back as 1 every time a new client relationship is created. Any ideas? Function $this->db->insert_id() to get last inserted record id always returns 1 - El Forum - 05-01-2014 [eluser]Andy UK[/eluser] FYI, I'm currently using Codeigniter version 2.0.1. I'll try upgrading to 2.1.4 to see if that helps... Function $this->db->insert_id() to get last inserted record id always returns 1 - El Forum - 05-01-2014 [eluser]Andy UK[/eluser] Upgraded to 2.1.4 and problem persists. Any help is much appreciated! Function $this->db->insert_id() to get last inserted record id always returns 1 - El Forum - 05-01-2014 [eluser]Andy UK[/eluser] For reasons unbeknownst to me, it is now working. The only change i made was switching from this Code: return $this->db->insert_id(); To this... Code: return mysql_insert_id(); Not strange in itself. But when I switched back again the first option worked too! No idea what's going on there, but it's working now. |