geckogully
asked on
last_insert_id always returns the same non-zero value
I am using last_insert_id to try to retrieve the id of the last record added to a table, just after the insert was done. The key field is auto_increment.
However, I ALWAYS get "Resource id #26", regardless of how many records there are in the table.
Even when the "next autoindex" figure (according to phpMyAdmin) is up around 31, I still get 26. I even tried completely clearing the table, but, there it was again - 26.
This is still a system in testing, and I am wondering if I have stuffed about with the table so much it needs rebuilding.
I am not sure what code or other details might be relevant.
All help appreciated!
Thanks,
Christine.
However, I ALWAYS get "Resource id #26", regardless of how many records there are in the table.
Even when the "next autoindex" figure (according to phpMyAdmin) is up around 31, I still get 26. I even tried completely clearing the table, but, there it was again - 26.
This is still a system in testing, and I am wondering if I have stuffed about with the table so much it needs rebuilding.
I am not sure what code or other details might be relevant.
All help appreciated!
Thanks,
Christine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you! To one for solving it, and to the other for explaining it.
ASKER
I am calling the mySQL utilities via functions (i am using php). I moved the mysql_insert_id one into the main part of the program, rather than via a function, but it still always returns zero.
Should I move the insert into the main program too, so that it is the very last statement executed before the mysql_insert_id?
Or does that not matter, as long as it was the last sql action called?
I have attached code from the main program, followed by the insert function code.
Christine.
Open in new window