我执行 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/56539421/