Python全系列 教程
3567个小节阅读:5931.7k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Python查询Mysql使用 fetchone() 方法获取单条数据, 使用fetchall() 方法获取多条数据。
xxxxxxxxxx
#导入模块
import pymysql
#创建连接
con = pymysql.connect(host='localhost',user='root',password='root',db='db_test',
charset='utf8')
#创建游标对象cursor
cursor=con.cursor()
sql='select * from t_user'
#执行sql
cursor.execute(sql)
#获取结果集
# result = cursor.fetchall()
# result = cursor.fetchmany(2)
result = cursor.fetchone()
print(result)
# print(cursor.rowcount)
实时效果反馈
1. Python查询Mysql数据库数据使用 ______方法获取单条数据, 使用fetchall()方法获取所有数据。
A fetchcount()
B fetchall()
C fetchmany()
D fetchone()
2. Python连接MySQL数据库,查询数据下划线处需要填写的代码是_____:
xxxxxxxxxx
sql='select * from t_user'
#执行sql
cursor.execute(sql)
#获取所有查询结果集
____________
print(result)
A result = cursor.fetchall()
B result = cursor.fetchone()
答案
1=>D 2=>A