I am trying to write a backend that will be used for an IOS app. I know it will be technically the wrong way to do it but it wont be deployed.
My issues is i get the error
self.cursor(query)
TypeError: 'CMySQLCursor' object is not callable
This happens when i run the following from main.py
import database
db = database.database()
staff = db.getData("SELECT * FROM timesheets.staff")
Finally this is my database.py
code
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()
Instead of:
self.cursor(query)
Try this:
self.cursor.execute(query)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.