#数据库连接方法
from pymysql import connect
def connect_mysql():
db_config = dict(host="sh-cynosdbmysql-grp-g8v0rcfk.sql.tencentcdb.com", port=23928, db="course", charset="utf8", user="root", passwd="Aa.1542306559")
try:
#**解包
cnx = connect(**db_config)
except Exception as err:
raise err
return cnx
查询到的数据转换成字典格式
db.cursor(cursor=pymysql.cursors.DictCursor)推荐!!!
扫描二维码,在手机上阅读!
评论