gpt4 book ai didi

mysql - 无法从变量插入表中的值

转载 作者:行者123 更新时间:2023-11-30 21:28:55 25 4
gpt4 key购买 nike

我正在尝试将值插入表中,但我无法执行此操作..我正在从 Enrty Widgets 获取值到一个变量并将它们放入数据库但不幸的是我得到了错误

我试过了,但是出错了

G_Name = Namee
G_Day = Value.day
G_Month = Value.month
G_Year = Value.year

sql = "insert into Birthdays (Name, Day, Month, Year) VALUES (%s, %d, %d,
%d) %"
val = (G_Name, G_Day, G_Month, G_Year)
mycursor.execute(sql, val)

它应该插入值但我收到以下错误:

"Failed processing format-parameters; %s" % err)
mysql.connector.errors.ProgrammingError: Failed processing format-
parameters; Python 'stringvar' cannot be converted to a MySQL type

最佳答案

我没有在 python 3.X 上工作过,但这是它在 python 2.7 上的工作方式

G_Name = Namee
G_Day = Value.day
G_Month = Value.month
G_Year = Value.year
mycursor = connection.cursor(prepared=True)
sql = """ insert into Birthdays (Name, Day, Month, Year) VALUES (%s, %d, %d, %d)"""
val = (G_Name, G_Day, G_Month, G_Year)
mycursor.execute(sql, val)
connection.commit()

我不知道,但您查询中的最后一个 % 应该在那里?

关于mysql - 无法从变量插入表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57345148/

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