gpt4 book ai didi

python - 如何获取最近插入行的主键值

转载 作者:行者123 更新时间:2023-11-29 04:48:51 24 4
gpt4 key购买 nike

import MySQLdb

如何在下面的执行中获取最近插入的行的主键值。

cursor = mysql.cursor()
cursor.execute("""INSERT INTO foos (val1,val2) VALUES (%s,%s)""", (v1, v2))

最佳答案

来自 the docs :

Cursor.lastrowid

This read-only attribute provides the rowid of the last modified row (most databases return a rowid only when a single INSERT operation is performed).

关于python - 如何获取最近插入行的主键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com