因此,我试图更新表,并且出于某种原因,该代码决定在执行时冻结。
import mysql.connector
cnx = mysql.connector.connect(user='user', password='password',
host='y u so interested',
database='discord')
cursor = cnx.cursor()
print ("Start")
update = ("UPDATE admin_daily_playtime_crp1 "
"SET DiscordName = %s "
"WHERE SteamName = %s ")
values = ("true", "Modern Mo")
cursor.execute(update, values)
cnx.commit()
print ("done")
答案 0 :(得分:0)
请考虑将表更新为包括内部每个列的正确数据类型。我将您的摘要更改为包括组织功能。调用函数discordName(Discord Name,Steam Name),它应该更新信息。我在自己的数据库上进行了测试,效果很好。
import mysql.connector
def connection():
connection = mysql.connector.connect(user='root', password='', host='',database='discord')
return connection
def discordName(discordName, steamName):
con = connection()
cursor = con.cursor()
print ("Start")
update = "UPDATE `admin_daily_playtime_crp1` SET `DiscordName` = %s WHERE `SteamName` = %s"
cursor.execute(update, (discordName, steamName))
print (cursor.rowcount, "record(s) affected!")
con.commit()
请问您还有其他问题! 这是我使用的https://gyazo.com/58dfd93e68ab4d452c896918f8ac2c8a
新表的图像