Python MySQL AttributeError: 'function' object has no attribute 'execute'
Python MySQL AttributeError: 'function' object has no attribute 'execute'
我正在尝试从 Python 的 MySQL 中的表中检索数据。但是我收到了
AttributeError: 'function' object has no attribute 'execute'
我的代码是:
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")
输出:
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'
您需要调用游标函数。所以将 cursor=mycon.cursor
替换为 cursor=mycon.cursor()
我正在尝试从 Python 的 MySQL 中的表中检索数据。但是我收到了
AttributeError: 'function' object has no attribute 'execute'
我的代码是:
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")
输出:
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'
您需要调用游标函数。所以将 cursor=mycon.cursor
替换为 cursor=mycon.cursor()