问题描述
我正在尝试编写一个将用于IOS应用程序的后端。我知道从技术上来说这是错误的方法,但不会部署。
我的问题是我得到了错误
self.cursor(query)
TypeError: 'CMysqLCursor' object is not callable
当我从main.py
运行以下命令时会发生这种情况
import database
db = database.database()
staff = db.getData("SELECT * FROM timesheets.staff")
最后这是我的database.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)