2011-07-23 48 views
4

可以使用pymysql爲我插入的行獲取ID?如何獲得插入到pymysql中的行的IDENTITY/AUTONUMBER值

curr = db.cursor() 
curr.execute("INSERT INTO `accounts` (`name`, `password`) VALUES ('%s', '%s')", accName, passwd) 
curr.execute("INSERT INTO `person` (`name`, `accoiunt_id`) VALUES ('%s', '%d')", pName, HERE_I_NEED_ACCID) 

會計表中有自動增加主鍵「id」。

+0

可能重複[您如何安全有效地在使用Python MySQLdb的MySQL的插入後,即可獲取行ID?](HTTP獲取結果作爲標:/ /stackoverflow.com/questions/706755/how-do-you-safely-and-efficiently-get-the-row-id-after-an-insert-with-mysql-usin) – jhonkola

回答