mysql连接器

whlutmcx  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(653)

所以我试图更新一个表,由于某种原因,这段代码决定在执行时冻结。

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

dfty9e19

dfty9e191#

考虑更新您的表以包含其中每一列的正确数据类型。我把你的狙击手改成了组织的成员。调用函数discorname(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()

如果你有更多的问题就问吧!这是我用过的新table的图片https://gyazo.com/58dfd93e68ab4d452c896918f8ac2c8a

相关问题