我想不出这里有什么问题。我一直得到的错误代码是“字符串格式化期间参数的数目错误”,但是我个人没有看到任何错误。有人能指点我正确的方向吗?谢谢。
def film_function(number, film):
connection = connect(host='localhost', user='root', \
passwd='', db='survey')
cursor = connection.cursor()
sql = "SELECT * FROM persons, persons_films WHERE persons.person = persons_films.person AND number_of_films >= %s AND film = '%s' ORDER BY persons_films.person"
cursor.execute(sql, [number], [film])
rows = cursor.fetchall()
if not rows:
print ("No one in "+film+" found!")
else:
for row in rows:
print row[0],"-", row[1]
cursor.close()
connection.close()
最佳答案
这个。。。
cursor.execute(sql, [number], [film])
应该是这样的:
cursor.execute(sql, [number, film])
您希望传递一个参数列表,而不是每个参数都有一个单独的列表。
关于python - Python/MySQL错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19393959/