首页 > 数据库技术 > 详细

pymysql连接数据库

时间:2021-06-04 12:09:45      阅读:15      评论:0      收藏:0      [点我收藏+]

import pymysql
from pymysql.cursors import DictCursor
res = pymysql.connect(‘localhost‘, ‘root‘, ‘123456‘, ‘2007a‘)
try:
res1 = res.cursor(DictCursor)
except: print(‘连接失败‘)
else: print(‘连接成功‘)
mystr = ‘1‘ mystr1 = ‘18‘
str = "select * from student where id=%s and age > %s"
try:
a = res1.execute(str,[mystr,mystr1])
except:
res.rollback()
print(‘查询失败‘)
else:
print(res1.fetchall())
print(str)
print(‘查询成功‘)
finally:
print(‘唱歌‘)
res.close()
res1.close()

pymysql连接数据库

原文:https://www.cnblogs.com/hutianxing/p/14848597.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!