![]() |
insert_id() not returning - 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: insert_id() not returning (/showthread.php?tid=3018) |
insert_id() not returning - El Forum - 09-05-2007 [eluser]Clooner[/eluser] Hello everybody. I'm using CI for a while now and I really like it. I made some applications with it already. I'm working on a larger site right now and need to get the last inserted id. I am using active records but no id is returned. What is a possible problem? The data is inserted correct. Code: function AddAdres($data) For the database I created a ID which is auto_increment and primary key. I'm using CI 1.5.4, PHP 4.3.10 and mysql 4.1.9 Hope someone has an answer. Thank you. insert_id() not returning - El Forum - 09-05-2007 [eluser]Clooner[/eluser] I fixed the problem myself with this workaround. Somehow CI has a bug with returning the last inserted id. Hope this helps someone else Code: function AddAdres($data) insert_id() not returning - El Forum - 10-26-2007 [eluser]maadmac[/eluser] [quote author="clooner" date="1189010010"]I fixed the problem myself with this workaround. Somehow CI has a bug with returning the last inserted id. Hope this helps someone else[/quote] Hi clooner, Thanks for pointing this out, I noticed the same problem. Did you find documentation on this somewhere? Is it indeed a bug, or perhaps just something else we might have overlooked? Thanks. insert_id() not returning - El Forum - 10-26-2007 [eluser]phester[/eluser] The CI function works fine for me... I am just a little curious how this behaves when you have more than one visitor at your site entering data at the same time. Will that query (or the CI insert_id() ) return the correct ID for the respective users? insert_id() not returning - El Forum - 10-26-2007 [eluser]maadmac[/eluser] It should. Here's the line from the doc: Quote:The insert ID number when performing database inserts. Even with multiple connections, the data are still written sequentially, so you should get the correct ID for that operation. insert_id() not returning - El Forum - 01-01-2008 [eluser]Zelaza[/eluser] Great work-around, clooner. I did some research and it looks like the underlying mysqli_insert_id() function is always returning 0 - so this may be a PHP or MySQL problem, not a CodeIgniter problem. insert_id() not returning - El Forum - 02-17-2008 [eluser]tomodian[/eluser] I had same problem, solved by this post. Thank you! insert_id() not returning - El Forum - 04-27-2009 [eluser]dizzu333[/eluser] Ok, I solved my problem with plain SQL as in this post. But shouldn't some one fix the incorrect behavior of db->insert_id() ? insert_id() not returning - El Forum - 04-27-2009 [eluser]Clooner[/eluser] [quote author="dizzu333" date="1240841513"]Ok, I solved my problem with plain SQL as in this post. But shouldn't some one fix the incorrect behavior of db->insert_id() ?[/quote] Seems like the fault of php and not CI... insert_id() not returning - El Forum - 04-27-2009 [eluser]dizzu333[/eluser] If I can retrieve the correct insert_id, couldn't CI do the same by using the insert_id() ? If a function doesn't have the correct behavior on a certain PHP version or by using function(s) that return incorrect results, that means that functions has bugs. A function should return the correct result no matter what. |