Name
insert_id( )*
Signature
id
=cursor.insert_id
( )
Synopsis
Returns the last inserted ID from the most recent
INSERT
on an AUTO_INCREMENT
field.
Example
connection = MySQLdb.connect(host='carthage', user='test', passwd='test', db='test'); cursor = connection.cursor( ); cursor.execute("INSERT INTO TNAME (COL) VALUES (1)"); id = cursor.insert_id( );
Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.