import pymysql
def Mysql(id):
conn = pymysql.connect( # 链接本地数据库
database="aaa",
host="localhost",
port=3306,
user="root",
password="123456",
charset="utf8"
)
curosr = conn.cursor() # 设置游标对象
curosr.execute("select * from exchange where user_id ={}".format(id)) # 执行sql语句
exc = curosr.fetchone() # 获取数据
# print(exc)
conn.close() # 关闭数据库连接
return exc
# 主函数入口
if __name__ == '__main__':
id = int(input("输入用户编号:")) # 输入用户编号查询信息
exc = Mysql(id)
网友评论