简体   繁体   English

获取刚用MySQL插入的行的自动编号ID

[英]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". 我正在使用INSERT在我的数据库中创建一个新记录,该记录由自动编号字段“product_id”标识。 Immediately after I insert the row, I need to get the ID of the new row so I can output the info for further processing. 插入行后,我需要立即获取新行的ID,以便输出信息以便进一步处理。 Is there any mysql function to get this ID? 有没有mysql函数来获取此ID?

LAST_INSERT_ID()返回自动生成的AUTO_INCREMENT值。

See: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html 请参阅: http//dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Note: this is assuming the c api. 注意:这是假设c api。

From the text: 从文字:

20.8.10.3. 20.8.10.3。 How to Get the Unique ID for the Last Inserted Row 如何获取最后插入行的唯一ID

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. 如果将记录插入到包含AUTO_INCREMENT列的表中,则可以通过调用mysql_insert_id()函数来获取存储在该列中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM