gpt4 book ai didi

python - MySQLDb 上的名称错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:01:31 25 4
gpt4 key购买 nike

我正在您的帐户系统上处理此 Python Credits,但似乎我的最后一个 for 循环未运行,导致 time_set 未定义。有谁知道为什么我的最后一个 for 循环没有运行。出于安全原因,数据库详细信息已被删除。这是我的代码:

from time import sleep
import MySQLdb
db = MySQLdb.connect(host="", # your host, usually localhost
user="", # your username
passwd="", # your password
db="") # name of the data base
cursor = db.cursor()#Defines a cursor allowing me to execute SQL commands
def timer(time, _print=False):
if time == 0:
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
cursor.execute("UPDATE Accounts SET Credits = 0 WHERE Username = '{1}';".format(creds, name))
return ''
else:
if _print: print time
sleep(1)
return timer(time - 1, _print)
name = raw_input("What username would you like to add credits to?:")
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
creds = input("How many credits would you like to add to the account?")
for test in cursor.fetchall():
creds = creds + test[3]
cursor.execute("UPDATE Accounts SET Credits = {0} WHERE Username = '{1}';".format(creds, name))
for row in cursor.fetchall():
time_set = creds * 60
print time_set
timer(time_set, True)

最佳答案

您似乎正在尝试从 UPDATE 查询中提取行,这将无济于事,因为 UPDATE 不返回任何行。

关于python - MySQLDb 上的名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27612050/

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