Initial commit
This commit is contained in:
39
create_menu_table.py
Normal file
39
create_menu_table.py
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
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()
|
Reference in New Issue
Block a user