开发者

Get the AutoNumber ID of a row just INSERTed with MySQL

开发者 https://www.devze.com 2023-02-09 21:56 出处:网络
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 o

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消