Python Forum
[mysql.connector] The database is never connected to and there are no errors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[mysql.connector] The database is never connected to and there are no errors
#1
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])))

    .
    .
    .
Reply


Messages In This Thread
[mysql.connector] The database is never connected to and there are no errors - by SheeppOSU - Jun-04-2020, 05:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Display name of a pc connected over lan fatopeo 1 1,423 Mar-16-2022, 10:10 AM
Last Post: Gribouillis
  mysql connector/telnet issue (re: text game) rebubula76 1 2,547 Feb-06-2018, 08:00 PM
Last Post: rebubula76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020