简体   繁体   中英

Storing Auto-Incremented ID when using PDO for MySQL

I'm using PDO with MySQL. I'm inserting into a table that has the ID field set to autoincrement. I'd like to store that value to reuse in the next line. How can I do this?

From PHP Manual:

Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. For example, PDO_PGSQL requires you to specify the name of a sequence object for the name parameter.

return $db->lastInsertId('yourIdColumn');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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