class database:
connection = None
def query(self, sql):
self.connection = mysql.connect(
host = "",
user = "",
passwd = "",
database = ""
)
cursor = self.connection.cursor()
cursor.execute(sql)
def queryAndFetchall(self,sql):
self.connection = mysql.connect(
host = "",
user = "",
passwd = "",
database = ""
)
cursor = self.connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
return result
def queryAndFetchone(self,sql):
self.connection = mysql.connect(
host = "",
user = "",
passwd = "",
database = ""
)
cursor = self.connection.cursor()
cursor.execute(sql)
result = cursor.fetchone()
return result
def commit(self):
self.connection.commit()
db = database()
class database:
connection = None
def query(self, sql):
self.connection = mysql.connect(
host = "",
user = "",
passwd = "",
database = ""
)
cursor = db.cursor()
cursor.execute(sql)
однако дайте совет как лучше написать методы в классе по вашему мнению.