Whole Software

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

RESTAURANT MANAGEMENT SYSTEM

RESTAURANT MANAGEMENT SYSTEM

import mysql.connector

from mysql.connector import Error

def create_connection():

try:

connection = mysql.connector.connect(

host='localhost',

database='resturant_db',

user='root',

password='Germany,Berlin',

charset='utf8'

if connection.is_connected():

print("Connected to MySQL database")

return connection

except Error as e:

print(f"Error: '{e}'")

return None

def close_connection(connection):

if connection.is_connected():

connection.close()

print("MySQL connection is closed")

===========================================================================
===========================================================================

DATABASES FILE ENDS HERE


RESTAURANT MANAGEMENT SYSTEM

MENU FILE STARTS HERE

from db import create_connection, close_connection

def add_menu_item(name, price, description):

connection = create_connection()

cursor = connection.cursor()

query = "INSERT INTO menu (name, price, description) VALUES (%s, %s, %s)"

values = (name, price, description)

cursor.execute(query, values)

connection.commit()

close_connection(connection)

print("Menu item added successfully.")

def view_menu():

connection = create_connection()

cursor = connection.cursor()

cursor.execute("SELECT * FROM menu")

rows = cursor.fetchall()

close_connection(connection)

return rows

def update_menu_item(item_id, name, price, description):

connection = create_connection()

cursor = connection.cursor()

query = "UPDATE menu SET name=%s, price=%s, description=%s WHERE id=%s"


RESTAURANT MANAGEMENT SYSTEM

values = (name, price, description, item_id)

cursor.execute(query, values)

connection.commit()

close_connection(connection)

print("Menu item updated successfully.")

def delete_menu_item(item_id):

connection = create_connection()

cursor = connection.cursor()

query = "DELETE FROM menu WHERE id=%s"

cursor.execute(query, (item_id,))

connection.commit()

close_connection(connection)

print("Menu item deleted successfully.")

You might also like