71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
|
|
import mysql.connector
|
|
|
|
# Database connection details
|
|
DB_HOST = "mysql.theaken.com"
|
|
DB_PORT = 33306
|
|
DB_NAME = "db_A027"
|
|
DB_USER = "A027"
|
|
DB_PASSWORD = "E1CelfxqlKoj"
|
|
|
|
try:
|
|
# Establish the connection
|
|
conn = mysql.connector.connect(
|
|
host=DB_HOST,
|
|
port=DB_PORT,
|
|
database=DB_NAME,
|
|
user=DB_USER,
|
|
password=DB_PASSWORD
|
|
)
|
|
cursor = conn.cursor()
|
|
|
|
# SQL statements to create tables
|
|
create_employee_table = """
|
|
CREATE TABLE IF NOT EXISTS employee (
|
|
id NVARCHAR(255) PRIMARY KEY,
|
|
name NVARCHAR(255)
|
|
)
|
|
"""
|
|
|
|
create_menu_items_table = """
|
|
CREATE TABLE IF NOT EXISTS menu_items (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
main_course NVARCHAR(255),
|
|
side_dish NVARCHAR(255),
|
|
addon NVARCHAR(255),
|
|
menu_date DATE
|
|
)
|
|
"""
|
|
|
|
create_employee_votes_table = """
|
|
CREATE TABLE IF NOT EXISTS employee_votes (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
emp_id NVARCHAR(255),
|
|
order_date DATE,
|
|
menu_item_id INT,
|
|
order_qty INT,
|
|
FOREIGN KEY (emp_id) REFERENCES employee(id),
|
|
FOREIGN KEY (menu_item_id) REFERENCES menu_items(id)
|
|
)
|
|
"""
|
|
|
|
# Execute the create table statements
|
|
cursor.execute(create_employee_table)
|
|
print("Table 'employee' created successfully.")
|
|
|
|
cursor.execute(create_menu_items_table)
|
|
print("Table 'menu_items' created successfully.")
|
|
|
|
cursor.execute(create_employee_votes_table)
|
|
print("Table 'employee_votes' created successfully.")
|
|
|
|
except mysql.connector.Error as err:
|
|
print(f"Error: {err}")
|
|
|
|
finally:
|
|
# Close the connection
|
|
if 'conn' in locals() and conn.is_connected():
|
|
cursor.close()
|
|
conn.close()
|
|
print("MySQL connection is closed.")
|