如何使用 Python 保存在 SQL 中所做的更改?
how to save the changes made in SQL using Python?
我使用 python 编写了代码以在 SQL 中输入数据。一切顺利,但当程序关闭时,所有输入的数据都丢失了。考虑这段代码。
os.system('cls')
nme = input("enter your name: ")
usid = input("enter your userID: ")
pasd = getpass.getpass("please enter a pin in digits, characters are not supported: ")
entry = """insert into users (name, ID, pin) values(%s, %s, %s)"""
data = (nme, usid, pasd)
curs.execute(entry, data)
curs.commit()
我在网上发现 curs.commit()
保存所做的更改,但显示错误。
this is what the compiler shows the error!!
从连接对象获取的游标仅用于 运行 查询。
如果您需要 Commit/Rollback 失败,请在 Connection 对象本身上执行此操作。
我使用 python 编写了代码以在 SQL 中输入数据。一切顺利,但当程序关闭时,所有输入的数据都丢失了。考虑这段代码。
os.system('cls')
nme = input("enter your name: ")
usid = input("enter your userID: ")
pasd = getpass.getpass("please enter a pin in digits, characters are not supported: ")
entry = """insert into users (name, ID, pin) values(%s, %s, %s)"""
data = (nme, usid, pasd)
curs.execute(entry, data)
curs.commit()
我在网上发现 curs.commit()
保存所做的更改,但显示错误。
this is what the compiler shows the error!!
从连接对象获取的游标仅用于 运行 查询。 如果您需要 Commit/Rollback 失败,请在 Connection 对象本身上执行此操作。