5

I want to check if I have managed to import my csv file into MySQL db in proper manner.My code

import MySQLdb

mydb = MySQLdb.connect(host = 'localhost',user = 'milenko',passwd = 'nuklear',db = 'mm')
cur = mydb.cursor()
command = cur.execute('SELECT * FROM jul')
results = command.fetchall()

print (results)

But I got this

File "b12.py", line 6, in <module>
    results = command.fetchall()
AttributeError: 'int' object has no attribute 'fetchall'

I have seen previous SO posts,where people claim that number objects do not have fetcall object.I have copied this code from Python for MySQL from Albert Lukaszewski. How to pull down db content in one go?

1 Answer 1

21

You can't call fetchall() on the result of a cursor.execute(), in fact, according to MySQLdb documentation, cursor.execute() return the number of affected rows by the query executed. To retrieve data you have to access to cursor results directly:

cur = mydb.cursor()
cur.execute('SELECT * FROM jul')
results = cur.fetchall()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.