import
pymysql;
db = pymysql.connect(host = "localhost",user = "root",
password = "root",db = "liupeng");#进入数据库#缓存
cur = db.cursor();
#查询
sql = "select * from user";
try :
cur.execute(sql);
results = cur.fetchall();#查询所有print("id","name","passwd","iamg");
for row in results:
id = row[0];
name = row[1];
passwd = row[2];
iamg = row[3];
print(id ,name ,passwd,iamg);
except Exception as e:
raise e; #触发异常finally: #无论代码是否错误,都执行最后一段
db.close();
#提示使用代码前要pip install pymysql ,数据库要设置好
原文:https://www.cnblogs.com/shenweizhi/p/10492056.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!