Files
ver1_ext/test_mysql_connection.py
2025-07-25 15:47:50 +08:00

27 lines
779 B
Python

import mysql.connector
def get_connection_details():
details = {}
with open('setting.txt', 'r') as f:
for line in f:
key, value = line.strip().split(':', 1)
details[key.strip()] = value.strip()
return details
try:
config = get_connection_details()
conn = mysql.connector.connect(
host=config.get('Host'),
port=config.get('Port'),
user=config.get('Username'),
password=config.get('Password'),
database=config.get('Database')
)
print("Connection successful!")
conn.close()
except ImportError:
print("Error: mysql-connector-python is not installed. Please install it using: pip install mysql-connector-python")
except Exception as e:
print(f"An error occurred: {e}")