批量打印查询结果:
#!/usr/bin/python
# !coding=utf-8
import pymysql
db = pymysql.connect(host='192.168.1.230', user='root', password='root',db='spiders', port=3306)
cursor = db.cursor()
sql = 'select * from students where age >33'
cursor.execute(sql)
print(cursor.rowcount)
result = cursor.fetchall()
for row in result:
print(row)
db.close()
如果结果集很大:
try:
while row:
print(row)
row = cursor.fetchone()
except:
print("ERROR")
批量打印查询结果
最新推荐文章于 2021-12-04 11:33:09 发布
