import pandas as pd
import mysql.connector as cnmsq
try:
cnkun = cnmsq.connect(user='root',
password='123456',
host='127.0.0.1',
database='dbkun')
except:
print"failed connect..."
cursor = cnkun.cursor()
aos_query = "SELECT is_accepted_name, accepted_id FROM kun_species WHERE species_name=%s"
acc_query = "SELECT species_family, species_genus, species_name, species_full_name FROM kun_species WHERE species_id=%d"
cursor.execute(aos_query, ('Linaria genistifolia',))
for id, acc_num in cursor:
print(id)
cursor.execute(acc_query, (acc_num,))
print([w for w in cursor])
如上,数据库连接成功之后,执行cursor.excute(acc_query,(acc_num,))
时候发生错误,将acc_query
的%d
改为%s
则程序可以完全正常的执行,但问题是acc_num
本身是int
型,为什么acc_query
内要用%s
而非%d
格式化它?
引发的错误:
Traceback (most recent call last):
....
"Not all parameters were used in the SQL statement")
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
L'instruction SQL doit être une chaîne,