gpt4 book ai didi

python - MySQL 语法错误?

转载 作者:行者123 更新时间:2023-11-29 06:12:28 24 4
gpt4 key购买 nike

我在论坛上搜索了运行代码时不断出现的错误,但它似乎是特定情况的。我的程序连接到数据库,从文本文件中获取一行,从该行中提取名称,然后使用该名称在数据库中执行搜索查询。相关代码如下:

while line:
lines = line.split('\t')
if len(lines) > 1:
date = lines[0]
name = lines[2]
address = lines[3]
amount = int(float(lines[len(lines)-1]))
named = name.split()
first = named[1]
last = named[0]
zipc = lines[4]
cur.execute("SELECT `Date`, `Contrib`, `Amount`, `Street`, `City`
`State`, `Zip` FROM indiv_contribs WHERE Contrib = '%s, %s'" %
(last, first))
rows = cur.fetchall()

我不断收到的错误是:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'malley, matthew'' at line 1"

最佳答案

如果您的语言是 Python,您的 SQL 语句应如下所示:

cur.execute("""SELECT Date, Contrib, Amount, Street, City, State, Zip FROM indiv_contribs WHERE Contrib = %s, %s""", (last, first))
rows = cur.fetchall()

关于python - MySQL 语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8320965/

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