You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|