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