Does the number of rows return?

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

+4
source share
1 answer

To answer your question:

Yes, it returns the number of requests, because you are connecting two operations: 1) getting the cursor 2) calling execute in one and accessing the final result in cur

2) the operation will result in an integer value that affects the number of rows that is stored in cur

0
source

Source: https://habr.com/ru/post/1659895/


All Articles