def get_mysql_credentials(self, configfile, dbms): """ Retrieve credentials from configuration file :param configfile: path to :param dbms: default is mysql :return: VOID """ try: if configfile: config = configparser.ConfigParser() config.read(configfile) self._host = config[dbms]['host'] self._username = config[dbms]['username'] self._password = config[dbms]['password'] self._database = config[dbms]['database'] self._run_transaction = config[dbms]['transactions'] except: print("Error: couldn't read config file")
def connect(self, database=None): """ Connect to a existing database :param database: name :return: the connection handler """ try: if database: # if is not Null self._database = database connection = pymysql.connect(self._host, self._username, self._password, self._database) return connection except pymysql.InternalError as error: print(error.args[1])