Python 无法使用特定id访问数据库中的数据
问题是您的查询是:Python 无法使用特定id访问数据库中的数据,python,python-2.7,pymysql,Python,Python 2.7,Pymysql,问题是您的查询是: import pymysql import os conn =pymysql.connect(host='localhost',database='pyp',user='root',password='') a = conn.cursor() h= raw_input('enter your id') sql='SELECT * from report WHERE Id = h' a.execute(sql) data=a.fetchall() print(data) c
import pymysql
import os
conn =pymysql.connect(host='localhost',database='pyp',user='root',password='')
a = conn.cursor()
h= raw_input('enter your id')
sql='SELECT * from report WHERE Id = h'
a.execute(sql)
data=a.fetchall()
print(data)
conn.close()
因此,您可以使用%s
指定一个参数,然后使用(列表)值调用.execute(..)
SELECT * from report WHERE Id = h
sql='SELECT * from report WHERE Id = %s'
a.execute(sql,(h,))