统计表格中的条数
#导入开发包
import pymysql.cursors
#获取链接
connection = pymysql.connect(
host='localhost',
user='root',
password='123456',
db='wikiurl',
charset='utf8mb4')
try:
#获取会话指针
with connection.cursor()as cursor:
#查询语句:统计表格中的条数
sql ="select `urlname`,`urlhref` from `urls` where `id` is not null"
count = cursor.execute(sql)
print(count)
finally:
connection.close()
#导入开发包
import pymysql.cursors
#获取链接
connection = pymysql.connect(
host='localhost',
user='root',
password='123456',
db='wikiurl',
charset='utf8mb4')
try:
#获取会话指针
with connection.cursor()as cursor:
#查询语句:统计表格中的条数
sql ="select `urlname`,`urlhref` from `urls` where `id` is not null"
count = cursor.execute(sql)
print(count)
#查询3条数据
result1 = cursor.fetchmany(size=3)
print(result1)
print("-------------------------------------------------------------")
#查询全部数据 输出的是第四条到最后的数据
result = cursor.fetchall()
print(result)
#这时候查询已经到了末尾,再进行数据查询只会输出(),没有具体的数据。
result2 = cursor.fetchmany(size=3)
print(result2)
finally:
connection.close()
网友评论