我正在尝试在mysql Query中传递一个变量,但该变量一直显示错误。
我很喜欢这个 https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html
NaN
但是会出现以下错误
mydb = mysql.connector.connect(
host="111.222.333.444.555",
user="user",
passwd="pass",
database="database_aname"
)
#print(mydb)
mycursor = mydb.cursor()
mycursor = mydb.cursor(buffered=True)
#lon=((data['hits']['hits'][i]['_source']['@timestamp']))
query = ("SELECT * from device_stock join customers on device_stock.user_id=customers.id WHERE device_stock.imei=%s")
#query = ("SELECT * from device_stock join customers on device_stock.user_id=customers.id WHERE device_stock.imei=0351777090784867")
mycursor.execute(query,(imei))
for row in mycursor:
print (row)
我该怎么办?
谢谢
答案 0 :(得分:0)
尝试
mycursor.execute(query,(imei,))
(imei)不视为元组。