pymysql安装
安装:
pip3 install PyMySQL
查看版本:
pip3 show pymysql
import pymysql
import xcodeSet
import os
from pymysql.cursors import DictCursor
def get_dataDic(sql):
sql = "SELECT * FROM `xxxx` WHERE `xxx` LIKE 'xxxx' LIMIT 0, 1000"
db = pymysql.connect(host='',user='',passwd='',db='',
charset='utf8')
#cur = db.cursor()
#以字典形式
cur = db.cursor(DictCursor)
dataDic = {}
try:
cur.execute(sql)
#描述名
#description = cur.description
fetchall = cur.fetchall()
dataDic = fetchall[0]
#cur.fetchone()
except Exception as e:
raise e
finally:
db.close()
print("---------------sql fetch complete:\n",dataDic)
return dataDic
网友评论