好吧,这就是错误Traceback (most recent call last): File "C:/Users/Mandem/PycharmProjects/untitled/Pranks/Lib/site-packages/Ada.py", line 161, in <module> mycursor.execute(updaterScoren) File "C:\Users\Mandem\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\cursor.py", line 546, in execute stmt = operation.encode(self._connection.python_charset)AttributeError: 'tuple' object has no attribute 'encode'Process finished with exit code 1这是我试图运行的命令 f = int(input( "Kodeord - bemærk her, at kodeordene er pinkoderne fra min egen database, bare indtast en værdi mellem 1-6")) mycursor.execute("SELECT id,adresse,name,pinkode_brugt,score FROM bois WHERE id=%s", (f,)) # MySQL Commands updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,)我是这样运行的:# MySQL Commands updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,) myresult = mycursor.fetchall() row_count = mycursor.rowcount print(myresult) print("number of affected rows: {}".format(row_count)) if row_count == 1: print(row_count) print(app.timerValue) while (i != app.timerValue) and (i <= app.timerValue) and (doorButton != 1) and (app.stopButton != 1): print('%.2f' % i) i = i + 0.01 timeLeft = app.timerValue - i iTwo = app.timerValue print("THIS IS X", app.timerValue) time.sleep(0.01) # Hvis spillet stoppes, or i ikke når timerens slutværdi, vil scoren gemmes if (i != app.timerValue): score = i print("Dette er dit resultat: {}".format('%.2f' %score)) mycursor.execute(updaterScoren)旁注,是否也可以使用“myresult”以某种方式来识别要更改/更新的行?所以,“更新pinkode_brugt WHERE row = Myresult”之类的东西
1 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
更改 updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,)
为 updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s" % f
应该可以完成工作,因为您错误地使用了格式变量
添加回答
举报
0/150
提交
取消