簡體   English   中英

Python MySQL AttributeError:“函數”對象沒有“執行”屬性

[英]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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM