Just-Moh-it / HotinGo

A 🐬 MySQL + 🐍 Python's Tkinter-based 🏖 Hotel Management System with a 😍 beautiful user interface.
https://www.figma.com/file/MVq5Q3fhVJB2r70r7I3nJ3
MIT License
192 stars 59 forks source link

Not Working – Unable to connect to mysql server #9

Closed RithvikPranav closed 1 year ago

RithvikPranav commented 1 year ago

it is throwning an exception saying that it is not allow to connect to Mysql Server

senthil221 commented 1 year ago

check the mysql connector

mammhoud commented 1 year ago

you can use sqlite or any sql server connector like Postgres over the mysql if you don`t have mysql


import sqlite3

class Database:

 path = './libs/'

    dbName = 'store.db'

    def __init__(self):
        self.connection = 
      sqlite3.connect(self.path+self.dbName)
        self.cursor = self.connection.cursor()

    def fetch_query(self, query):
        self.cursor.execute(query)
        results = self.cursor.fetchall()
        return results

    def fetch_columns_names(self, table_name):
        query = "PRAGMA table_info({})".format(table_name)
        results = self.fetch_query(query)
        columns_names = []
        print(results)
        for row in results:
            if row[1]!='id':
                columns_names.append(row[1])
        self.connection.commit()

        return columns_names

    def create_table(self, table_name, columns):
        query = "CREATE TABLE IF NOT EXISTS {} ({})".format(table_name, columns)
        self.cursor.execute(query)

    def insert_data(self, table_name, data):
        query = "INSERT INTO {} ({}) VALUES ({})".format(table_name,self.fetch_columns_names(table_name), data).replace('[', '').replace(']', '')
        print(query, "--------> Running ")

        self.cursor.execute(query)
        self.connection.commit()
        self.close_connection()

    def select_data(self, table_name, where_clause=None,fetchall = True):
        query = f"SELECT * FROM {table_name} {where_clause}"
        if where_clause:
            query = query.format(where_clause)
        print(query, "--------> Running ")
        self.cursor.execute(query)
        if fetchall ==False:
            results01 = self.cursor.fetchone()

        else: 
            results01 = self.cursor.fetchall()
        self.connection.commit()
        self.close_connection()

        return results01
SnazzyCoder commented 1 year ago

I think this was a localhost connector problem 🙃 Closing this... feel free to create another issue if this issue still persists :)