Jun-04-2020, 05:36 AM
I made a class to manage a database, but there's a problem with connecting to the database. Line 11 just runs without any errors. If there was an error it should've printed on line 19, and I also tried removing the try statement, but still no error, it just runs continuously as the print statement on line 12 is never executed. Idk if it's the code or some other problem. Thanks in advance for any help.
import mysql.connector as conn . . . class DataBase: def __init__(self): try: print("Looking for database") self.db = conn.connect(host="127.0.0.1", port=8080, user="---------", passwd="----------", database="Socket_Online_Games_Database") print("Found already existing database") self.cursor = self.db.cursor() cursor.execute("SHOW TABLES") for table in tables: if table not in cursor: self.cursor.execute("CREATE TABLE %s (%s)" % (table, ", ".join(tables[table]))) except Exception as err: print(err) self.db = conn.connect(host="127.0.0.1", port=8080, user="---------", passwd="-----------") self.cursor = self.db.cursor() self.cursor.execute("CREATE DATABASE Socket_Online_Games_Database") print("Made new database") for table in tables: self.cursor.execute("CREATE TABLE %s (%s)" %(table, ", ".join(tables[table]))) . . .