import mysql.connector import logging logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG) class DBConnection(): def __init__(self): self.dbconnection = None def connect(self, host, user, password, database): self.connection= mysql.connector.connect(host=host, user=user,password=password,database=database) logging.debug(f'Datenbankverbindung aufgebaut ${self.connection}') logging.debug(f'Cursor gesetzt ${self.cursor}') def disconnect(self): if self.connection is not None: self.connection.close() def isConnected(self): # logging.debug(f'connection={self.connection}') # logging.debug(f'connected= {self.connection.is_connected()}') if self.connection is not None: return self.connection.is_connected() return False def cursor(self): if self.isConnected(): return self.connection.cursor() return None def insert(self,cmd): pass def fetch(self): pass def create_table(self): pass def execute_query(self, query, params = None): if self.isConnected(): cursor = self.cursor() if cursor is not None: cursor.execute(query,params) return cursor.fetchall()