Initial commit
This commit is contained in:
35
update_table.py
Normal file
35
update_table.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import mysql.connector
|
||||
|
||||
# Database connection details from the user's file
|
||||
config = {
|
||||
'user': 'A027',
|
||||
'password': 'E1CelfxqlKoj',
|
||||
'host': 'mysql.theaken.com',
|
||||
'port': 33306,
|
||||
'database': 'db_A027'
|
||||
}
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
cnx = mysql.connector.connect(**config)
|
||||
cursor = cnx.cursor()
|
||||
|
||||
# SQL statement to modify the column
|
||||
alter_table_query = "ALTER TABLE orders MODIFY COLUMN main_course VARCHAR(255)"
|
||||
|
||||
# Execute the query
|
||||
cursor.execute(alter_table_query)
|
||||
|
||||
# Commit the changes
|
||||
cnx.commit()
|
||||
|
||||
print("資料表修改成功!")
|
||||
|
||||
except mysql.connector.Error as err:
|
||||
print(f"資料庫錯誤: {err}")
|
||||
finally:
|
||||
# Close the connection
|
||||
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