更新挂起代码-Python MySQL Connector

时间:2018-10-13 02:50:30

标签: python mysql sql-update mysql-connector hang

因此,我试图更新表,并且出于某种原因,该代码决定在执行时冻结。

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")

表格设置: https://gyazo.com/dde9475d33056b26c04d564e3e8f7349

1 个答案:

答案 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

新表的图像