Python MySQLdb equivalent for PHP’s mysql_insert_id()
What you’re looking for is lastrowid property of a cursor object.
Code:
import MySQLdb # MySQLdb module must be installed on the system connection = MySQLdb.connect(...) # Details skipped cursor = connection.cursor() query = "INSERT INTO ... " # put query here cursor.execute(query) print cursor.lastrowid # BINGO! This will print the id (auto-increment column) of the last inserted row # Other codes here
Thanks to this article on the Internet
philihp 10:31 pm on February 12, 2012 Permalink |
I’m glad it was useful for someone
Shafiul Azam 11:46 pm on February 12, 2012 Permalink |
Haha…. lol