python3 pymysql查询结果包含字段名
python2使用MySQLdb模块进行连接mysql数据库进行操作;python3则使用pymysql模块进行连接mysql数据库进行操作;两者在语法上有稍微的差别,其中就包括查询结果包含字段名,具体例子如下:
python2:
import MySQLdb
conn = MySQLdb.connect(host=‘127.0.0.1‘,user=‘root‘,passwd=‘root‘,db=‘adu‘)
cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
sql = ‘select * from test1‘
reCount = cur.execute(sql)
nRet = cur.fetchall()
cur.close()
conn.close()
print(nRet)
print(reCount)
pytnon3:
import pymysql
conn = pymysql.connect(host=‘127.0.0.1‘,user=‘root‘,passwd=‘root‘,db=‘adu‘)
cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
sql = ‘select * from test1‘
reCount = cur.execute(sql)
nRet = cur.fetchall()
cur.close()
conn.close()
print(nRet)
print(reCount)
相关推荐
JamesRayMurphy 2020-05-31
愿天下再无BUG 2020-06-25
阿亮 2020-06-22
liuweiq 2020-06-14
variab 2020-06-14
sunnyxuebuhui 2020-06-04
测试自动化顾问 2020-05-29
heniancheng 2020-05-26
huolan 2020-05-12
kuwoyinlehe 2020-05-07
zjyhll 2020-05-06
huangliang00 2020-05-03
sulindong0 2020-04-30
探索世界改变世界 2020-04-21
jhshanyu00 2020-04-20
bcbeer 2020-04-16
会哭的雨 2020-03-26