Files
order_system2/create_menu_table.py
2025-09-16 12:38:41 +08:00

40 lines
1001 B
Python

import mysql.connector
# DB credentials
config = {
'user': 'A027',
'password': 'E1CelfxqlKoj',
'host': 'mysql.theaken.com',
'port': 33306,
'database': 'db_A027'
}
TABLES = {}
TABLES['menu_items'] = (
"CREATE TABLE `menu_items` ("
" `id` int NOT NULL AUTO_INCREMENT,"
" `main_course` varchar(255) NOT NULL,"
" `side_dish` varchar(255) DEFAULT NULL,"
" `addon` varchar(255) DEFAULT NULL,"
" `menu_date` date NOT NULL,"
" PRIMARY KEY (`id`)"
") ENGINE=InnoDB")
try:
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
cursor.execute("DROP TABLE IF EXISTS menu_items")
table_description = TABLES['menu_items']
cursor.execute(table_description)
print("資料表 'menu_items' 建立成功!")
except mysql.connector.Error as err:
print(f"資料庫錯誤: {err}")
finally:
if 'cursor' in locals() and cursor:
cursor.close()
if 'cnx' in locals() and cnx.is_connected():
cnx.close()