2

I am trying to retrieve data from tables in MySQL on Python. But I have received

AttributeError: 'function' object has no attribute 'execute'

My code is:

import mysql.connector as sqltor
mycon=sqltor.connect(host="localhost",user="root",passwd=" ",database="revision")
if mycon.is_connected():
    print("Successfully Connected to MySQL database.")
else:
    print("Check yo inputs, they really correct?")

cursor=mycon.cursor
cursor.execute("select*from account")

Output:

Successfully Connected to MySQL database.
Traceback (most recent call last):
  File "C:/Users/biina/Documents/Python/Apparel store/Python/Practical File/Interface_Python_with_MySQL.py", line 10, in <module>
    cursor.execute("select*from account")
AttributeError: 'function' object has no attribute 'execute'
5
  • 1
    Can you clean up your post a bit? There should be an "edit" button and the interface when asking a question should also explain how to format code, for example. Commented Oct 23, 2020 at 13:14
  • 1
    I did not double check the structure after posting so thank you for pointing it out! Commented Oct 23, 2020 at 13:37
  • 1
    Already fixed that for you. Don't know if the changes have been approved already. Commented Oct 23, 2020 at 13:38
  • 1
    Hi there, I have approved the suggestion so the post looks perfect from my view, I hope its the same for others. Im new here so thank you for fixing it :) Commented Oct 23, 2020 at 16:04
  • stackoverflow.com/questions/34337452/… Commented Nov 24, 2022 at 15:07

1 Answer 1

8

You need to call the cursor function. So replace cursor=mycon.cursor with cursor=mycon.cursor()

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.