首页 > 数据库技术 > 详细

python查询mysql以字典返回

时间:2018-09-27 15:10:06      阅读:172      评论:0      收藏:0      [点我收藏+]
# *_*coding:utf-8 *_*
import pymysql

conn = pymysql.connect(host=‘192.168.33.10‘, user=‘root‘, passwd=‘root‘, db=‘spider‘, charset=‘utf8‘)
cur = conn.cursor(cursor=pymysql.cursors.DictCursor)

sql = "select * from topic order by id asc "
cur.execute(sql)  # 返回受影响的行数
res = cur.fetchall()  # 返回数据,返回的是tuple类型

for item in res:
    print(item[‘id‘])
cur.close()
conn.close()

  

python查询mysql以字典返回

原文:https://www.cnblogs.com/php-linux/p/9712923.html

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