MySQL :: MySQL Connector/Python Developer Guide :: 10.5.19 MySQLCursor.lastrowid Property (original) (raw)

10.5.19 MySQLCursor.lastrowid Property

Syntax:

id = cursor.lastrowid

This read-only property returns the value generated for anAUTO_INCREMENT column by the previousINSERT orUPDATE statement orNone when there is no such value available. For example, if you perform anINSERT into a table that contains an AUTO_INCREMENT column,lastrowid returns theAUTO_INCREMENT value for the new row. For an example, seeSection 5.3, “Inserting Data Using Connector/Python”.

The lastrowid property is like themysql_insert_id() C API function; see mysql_insert_id().