我正在尝试使用以下命令插入 MYSQL 数据库:
add_contact = "INSERT INTO contacts (id, name, industry, phone, fax, url, pobox, emirate,ranking) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
data_contact = (0, fields[2], fields[0], fields[5], fields[6], fields[1], fields[3], fields[4], float(totalhits))
cursor.execute(add_contact, data_contact)
我收到以下错误:
Traceback (most recent call last):
File "reputation.py", line 53, in <module>
cursor.execute(add_contact, data_contact)
File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 381, in execute
"Wrong number of arguments during string formatting")
mysql.connector.errors.ProgrammingError: Wrong number of arguments during string formatting
这让我怀疑我数到 9 的能力:-)
这段代码可能有什么问题?
更新:
更改为
add_contact = ("INSERT INTO 联系人(id、姓名、行业、电话、传真、url、邮箱、酋长国、排名)" "VALUES (%s,%s,%s,%s,%s,%s,%s ,%s,%s)")
加
cnx.commit()
解决了!
谢谢!