Get the AutoNumber ID of a row just INSERTed with MySQL
I am using an INSERT to create a new record in my database which is identified by an autonumber field "product_id". Immediately after I insert the row, I need to get the ID of the new row so I can output开发者_StackOverflow中文版 the info for further processing. Is there any mysql function to get this ID?
LAST_INSERT_ID() returns automatically generated AUTO_INCREMENT value.
See: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
Note: this is assuming the c api.
From the text:
20.8.10.3. How to Get the Unique ID for the Last Inserted Row
If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function.
精彩评论