統(tǒng)計表格中的條數(shù)
#導(dǎo)入開發(fā)包
import pymysql.cursors
#獲取鏈接
connection = pymysql.connect(
host='localhost',
? ? user='root',
? ? password='123456',
? ? db='wikiurl',
? ? charset='utf8mb4')
try:
#獲取會話指針
? ? with connection.cursor()as cursor:
#查詢語句:統(tǒng)計表格中的條數(shù)
? ? ? ? sql ="select `urlname`,`urlhref` from `urls` where `id` is not null"
? ? ? ? count = cursor.execute(sql)
print(count)
finally:
connection.close()
#導(dǎo)入開發(fā)包
import pymysql.cursors
#獲取鏈接
connection = pymysql.connect(
host='localhost',
? ? user='root',
? ? password='123456',
? ? db='wikiurl',
? ? charset='utf8mb4')
try:
#獲取會話指針
? ? with connection.cursor()as cursor:
#查詢語句:統(tǒng)計表格中的條數(shù)
? ? ? ? sql ="select `urlname`,`urlhref` from `urls` where `id` is not null"
? ? ? ? count = cursor.execute(sql)
print(count)
#查詢3條數(shù)據(jù)
? ? ? ? result1 = cursor.fetchmany(size=3)
print(result1)
print("-------------------------------------------------------------")
#查詢?nèi)繑?shù)據(jù)? 輸出的是第四條到最后的數(shù)據(jù)
? ? ? ? result = cursor.fetchall()
print(result)
#這時候查詢已經(jīng)到了末尾味抖,再進(jìn)行數(shù)據(jù)查詢只會輸出()孟辑,沒有具體的數(shù)據(jù)羹饰。
? ? ? ? result2 = cursor.fetchmany(size=3)
print(result2)
finally:
connection.close()