Python:MySQLdb:错误:1064“您的 SQL 语法有错误。”

发布于 2024-10-19 12:58:41 字数 468 浏览 4 评论 0原文

我是 MySQLdb 和 Python 的新手。我正在尝试执行以下语句:

header_string = 'number_one, number_two, number_three'
values = '1, 2, 3'
cursor.execute("""INSERT INTO my_table (%s) VALUES (%s)""", (header_string, values))

它返回以下错误:

错误:1064“您的 SQL 语法中有错误。”

根据我对 MySQLdb 的有限理解,上面的执行语句应该执行以下 SQL 语句:

INSERT INTO my_table (number_one, number_two, number_three) VALUES (1, 2, 3)

知道我可能做错了什么吗?

I'm new to MySQLdb and Python. I'm trying to execute the following statement:

header_string = 'number_one, number_two, number_three'
values = '1, 2, 3'
cursor.execute("""INSERT INTO my_table (%s) VALUES (%s)""", (header_string, values))

and it returns with the following error:

Error: 1064 "You have an error in your SQL syntax."

From my limited understanding of MySQLdb the above execute statement should execute the following SQL statement:

INSERT INTO my_table (number_one, number_two, number_three) VALUES (1, 2, 3)

Any ideas what I might be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素食主义者 2024-10-26 12:58:41

尝试:

header_string = ('number_one','number_two','number_three')
values = (1,2,3)
cursor.execute("""INSERT INTO my_table (%s,%s,%s) VALUES (%s,%s,%s)""", (header_string+values))

Try:

header_string = ('number_one','number_two','number_three')
values = (1,2,3)
cursor.execute("""INSERT INTO my_table (%s,%s,%s) VALUES (%s,%s,%s)""", (header_string+values))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文