Is possible to get ID for the row I inserted using pymysql?
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)
There is autoincrement primary key "id" in accounts table.
You can use lastrowid
property of your cursor object.
Or you can execute SELECT LAST_INSERT_ID()
, and fetch the result as scalar with fetchone()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With