This is my MySQL database:
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;
I use PyMySQL to connect it, and then I do this:
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()]
He raised this:
AttributeError: 'int' object has no attribute 'fetchall'
I try type(cur)and obviously I gotint
I try print(cur)and I got0
After insert blogs(title,text) values ('222','qwqwqwq'); print(cur)=1
After insert blogs(title,text) values ('333','qwqw222'); print(cur)=2
Is a curstring blogs?
And how could I achieve entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]?
Help me thanks
source
share