python中,mysql数据库中查询结果用下列语句赋值给cursor变量cursor=con.execute('select * from test')然后用下面语句取出所有查询结果并赋值给rowsrows=cursor.fetchall()结果报错如下AttributeError: 'long' object has no attribute 'fetchall'请问cursor是什么数据类型,不能直接使用fetchall()方法么?
3 回答
Helenr
TA贡献1780条经验 获得超3个赞
conn = connectDB() # "oceantest"
with conn.cursor() as cursor:
sql = "select * from test limit 10" # 在test表中取出十条数据
search_count = cursor.execute(sql)
result = cursor.fetchall()
慕村9548890
TA贡献1884条经验 获得超4个赞
def getallinfo(x,y):
#x为数据库,y为sql
coon=pymysql.connect(user='root',passwd='123456',db=x,port=3306,host='127.0.0.1',charset='utf8')
cursor=coon.cursor()
cursor.execute(y)
res=cursor.fetchall()
cursor.close()
coon.close()
return res
ibeautiful
TA贡献1993条经验 获得超5个赞
你这是用python来执行数据库查看的操作吧
import pymysql
conn = pymysql.connect(user ='root',password ='你的密码',db = 'test所在的库')
cursor = conn.cursor()
count = cursor.execute('select * from test')
data = cursor.fetchall
print(data)
添加回答
举报
0/150
提交
取消