【问题标题】:how to save the changes made in SQL using Python?如何使用 Python 保存在 SQL 中所做的更改?
【发布时间】:2021-04-04 11:01:13
【问题描述】:

我编写了一个代码来使用 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!!

【问题讨论】:

  • 光标用于运行查询。请提交提供光标的连接变量。
  • @mangupt 是的,我找到了!!非常感谢!!

标签: python mysql syntax-error


【解决方案1】:

从连接对象获得的光标仅用于运行查询。 如果您需要在失败时提交/回滚,请在 Connection 对象本身上执行此操作。

【讨论】:

    猜你喜欢
    • 2012-12-31
    • 2021-03-14
    • 2017-05-30
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2018-06-26
    • 2012-08-28
    • 2017-11-05
    相关资源
    最近更新 更多