更新挂起代码 -- Python MySQL Connector
Update hangs code -- Python MySQL Connector
所以我正在尝试更新 table 并且出于某种原因,此代码决定在执行时冻结。
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")
Table 设置:
https://gyazo.com/dde9475d33056b26c04d564e3e8f7349
考虑更新您的 table 以包含其中每一列的正确数据类型。我更改了您的代码片段以包含组织功能。调用函数 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
的新 table 的图像
所以我正在尝试更新 table 并且出于某种原因,此代码决定在执行时冻结。
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")
Table 设置: https://gyazo.com/dde9475d33056b26c04d564e3e8f7349
考虑更新您的 table 以包含其中每一列的正确数据类型。我更改了您的代码片段以包含组织功能。调用函数 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
的新 table 的图像