flaquito
-
Posts
1 -
Joined
-
Last visited
Never
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
[SOLVED] get the autoincrement value of newly inserted row
in PHP Coding Help
Posted
Hello,
Is there a function to get the value of an autoincrement (or any field) back after inserting a new row ?
example
INSERT INTO tbl_name (col2,col3) VALUES(firstname, lastname);
col1 is an autoincrement.
How can you get the value of col1 of the new row back ?
kind regards
anatak
[/quote]
Have a look at
[code]SELECT LAST_INSERT_ID()[/code]
You don't have to return the entire table (?!?), and it's connection based, so you don't have to worry about race conditions. Check the documentation at [url=http://href=http://dev.mysql.com/doc/refman/5.0/en/information-functions.html]href=http://dev.mysql.com/doc/refman/5.0/en/information-functions.html[/url], about halfway down the page.