立即学习:https://edu.csdn.net/course/play/24756/280728?utm_source=blogtoedu
fetch查找:
1.fetchone():每次只获取一条数据:
import pymysql
db=pymysql.connect(host="127.0.0.1",port=3306,user="root",password="123456",database="csdn-study")
cursor=db.cursor()
sql="select id,title from article"
cursor.execute(sql)
result=cursor.fetchone()
print(result)
2.fetchall():接收全部返回结果:
result=cursor.fetchall()
3.fetchmany(size):获取指定条数的数据:
result=cursor.fetchmany(3)