pymysql查询,返回字典格式。

时间:2021-06-16 18:09:26   收藏:0   阅读:0

使用:pymysql.cursors.DictCursor

直接上代码

import pymysql

db = pymysql.connect(host = "host", user = "user", password = "password", database = "database")
cursor = db.cursor(pymysql.cursors.DictCursor)

sql = "SELECT `id`,`name` FROM `student`;"
cursor.execute(sql)
data_list = cursor.fetchall()
cursor.close()
db.close()

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!