MySQLdb Fetching results

In the previous post we have seen how to execute sql queries using execute()  method. execute()  method returns affected rows, it doesn’t return the result. To fetch result we use the fetchall()  method of the cursor object

Syntax: cursor.fetchall()

On success it returns tuple of rows where each row is a tuple.

above code will print all the rows in the city table.

You can also use for loop to iterate over the results.

Some more examples.

Example 1:

Example 2:

 

Leave a Reply

2 Comments on "MySQLdb Fetching results"

Notify of
avatar

Sort by:   newest | oldest | most voted
Ken Clement
Guest
Ken Clement
1 year 2 months ago

Syntax: cursor.fethcall() should instead read: Syntax: cursor.fetchall()

There is a letter transposition in fetchall – should be ‘ch’ instead of ‘hc’

wpDiscuz