gpt4 book ai didi

Python 不更新表

转载 作者:行者123 更新时间:2023-11-29 15:36:30 25 4
gpt4 key购买 nike

我正在尝试使用 Python 制作数据库 GUI 应用程序,但无法更新表。没有错误,但我在查看 Mysql 工作台后运行程序没有任何变化。

class DB:
def __init__(self):
self.conn = mysql.connector.connect(host='localhost', database='databese', user='user',
password='password')
self.cur = self.conn.cursor()
self.conn.commit()

def update(self, isim):
self.conn.commit()
self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)

def updateback(self, isim):
self.cur.execute("UPDATE hakemler SET durum='UYGUN' WHERE isim='%s'",isim)
self.conn.commit()
db = DB()

def çıkar():
db.update(id.get())
def gerial():
db.updateback(hakem1.get())
hakem = StringVar()
hakem1= StringVar()
id = IntVar()
entry1 = tk.Entry(mazeretli, width=20, textvariable=id)
entry1.grid(row=1, column=1)
button1 = tk.Button(mazeretli, text="Kişiyi Listeden Çıkar", command=çıkar)
button1.grid(row=2, column=2)
entry2 = tk.Entry(mazeretli, width=20, textvariable=hakem1)
entry2.grid(row=3, column=1)
button2 = tk.Button(mazeretli, text="Kişiyi Geri Al", command=gerial)
button2.grid(row=4, column=2)

没有错误信息或者其他什么。代码根本不起作用

最佳答案

您的问题在这里:

def update(self, isim):
self.conn.commit()
self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)

数据库操作要求您在操作后提交,以便将更改写入数据库。你把顺序颠倒了。更换顺序:

def update(self, isim):
self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)
self.conn.commit()

关于Python 不更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58192564/

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