mysql-python: How can I retrieve the ID of the last record I added?

Sam Penrose sam at ddmweb.com
Fri Sep 28 16:58:52 EDT 2001


Oleg wrote:
> SELECT LAST_INSERT_ID()

You can also do it through MySQLdb. 

connection = MySQLdb.connect(host='host', user='user', passwd='passwd',
db='database')
#insert a record, then
last_id = connection.db.insert_id()





More information about the Python-list mailing list