Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MySQL connect时的Python OOP编程问题_Python_Python 3.x_Mysql Python_Python 3.8 - Fatal编程技术网

使用MySQL connect时的Python OOP编程问题

使用MySQL connect时的Python OOP编程问题,python,python-3.x,mysql-python,python-3.8,Python,Python 3.x,Mysql Python,Python 3.8,我正在尝试编写一个用于IOS应用程序的后端。我知道这在技术上是错误的,但它不会被部署 我的问题是我得到了错误 self.cursor(query) TypeError: 'CMySQLCursor' object is not callable 当我从main.py import database db = database.database() staff = db.getData("SELECT * FROM timesheets.staff") 最后,这是我的

我正在尝试编写一个用于IOS应用程序的后端。我知道这在技术上是错误的,但它不会被部署

我的问题是我得到了错误

self.cursor(query)
TypeError: 'CMySQLCursor' object is not callable
当我从
main.py

import database


db = database.database()

staff = db.getData("SELECT * FROM timesheets.staff")
最后,这是我的
数据库.py
代码

import mysql.connector

class database :
    conn = ""
    cursor = ""

    def __init__(self):
        self.conn = mysql.connector.connect(user='james',
                                       password='timeismoney',
                                       host='hallfamily.mycrestron.com',
                                       database='timesheets',
                                       port='6033')

        self.cursor = self.conn.cursor()

        print("Done")

    def getData(self, query):

        #Checking if the user has applied a string
        if isinstance(query, str):
            self.cursor(query)
        else:
            return "You have provided a request that cant be processed"

        #Fetching all the results
        result = self.cursor.fetchall()

        #Returning back to the user
        return result

    def postData(self):
        print("Coming soon")


    def close(self):
        self.conn.close()
而不是:

self.cursor(query)
试试这个:

self.cursor.execute(query)

这就解决了问题。非常感谢。由于找不到官方文件,我可以使用任何官方文件吗。