Python/MySQL 错误

标签 python mysql

我不知道这里的问题是什么。我不断收到的错误代码是“字符串格式化期间参数数量错误”,但我个人没有发现任何问题。谁能指出我正确的方向?谢谢。

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/MySQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393959/

相关文章:

python - 一列热编码多个分类数据

python - 如何过滤多年数据帧以保留所有年份中具有值的行

python - 尝试制作网络爬虫来解析网站链接时接收和空列表

mysql - 合并两个查询以在 mysql 中获取结果

MYSQL 选择事件日期的记录

mysql - 选择 WHERE IN(子查询)

c# - 从 c# 服务器到 mysql DB - 希伯来语问号

python - 如何在具有分层索引的 pandas 数据框中添加和计算(基于其他列)子列?

Python 正则表达式 : How to implement a regex expression that checks for matching set of brackets?

mysql - 如何使用 Node 从 MySQL 数据库获取数据