我执行一个 INSERT INTO 语句
cursor.execute("INSERT INTO mytable(height) VALUES(%s)",(height))
我想得到主键。
我的表有 2 列:
id primary, auto increment
height this is the other column.
我刚刚插入后如何获得“id”?
最佳答案
使用 cursor.lastrowid
获取插入游标对象的最后一行 ID,或使用 connection.insert_id()
获取该连接上最后插入的 ID .
关于python - 如何在使用 Python 插入 MySQL 数据库后获取 "id"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2548493/