python – 它是否返回行数?
发布时间:2020-12-20 13:14:58 所属栏目:Python 来源:网络整理
导读:这是我的 MySQL数据库: create table 'blogs' ( 'id' int(10) primary key auto_increment,'title' varchar(29) not null,'text' varchar(500) not null) engine=innodb default charset=utf8mb4; 我使用PyMySQL连接它,然后我这样做: cur = connection.cur
这是我的
MySQL数据库:
create table 'blogs' ( 'id' int(10) primary key auto_increment,'title' varchar(29) not null,'text' varchar(500) not null ) engine=innodb default charset=utf8mb4; 我使用PyMySQL连接它,然后我这样做: cur = connection.cursor().execute('select title,text from blogs order by id desc') entries = [dict(title=row[0],text=row[1]) for row in cur.fetchall()] 它提出了这个: AttributeError:’int’对象没有属性’fetchall’ 我尝试输入(cur),显然我得到了int 我尝试打印(cur),我得到0 插入博客(标题,文本)值后(‘222′,’qwqwqwq’);打印(当前)= 1 插入博客(标题,文本)值后(‘333′,’qwqw222’);打印(当前)= 2 是博客的行吗? 我怎样才能在cur.fetchall()中获得条目= [dict(title = row [0],text = row [1])? 帮帮我,谢谢 解决方法
回答你的问题:
是的,它确实返回了多个查询,因为你链接了两个操作1)获取游标2)在一个中调用execute并在cur中引用最终结果 2)操作将产生整数值,该值给出受影响的行数,该行存储在cur中 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |