fetchall()将结果放在二维数组里面,每一行的结果在元组里面
import pymysql
def export(table_name):
conn =pymysql.connect(host = '118.24.3.40',
user = 'jxz',password='',
db='jxz',port=3306,charset = 'utf8')
cur = conn.cursor()
cur.execute('select * from %s'%table_name)
print(cur.fetchall())
export('app_student')
想返回字典格式,只需要在建立游标的时候加个参数,cursor=pymysql.cursors.DictCursor。这样每行返回的值放在字典里面,然后整体放在一个list里面。
import pymysql
def export(table_name):
conn =pymysql.connect(host = '118.24.3.40',
user = 'jxz',password='',
db='jxz',port=3306,charset = 'utf8')
cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
cur.execute('select * from %s'%table_name)
print(cur.fetchall())
export('app_student')