import pymysql
def test_db_connection():
# Database connection parameters
host = 'your-database-host'
user = 'your-database-username'
password = 'your-database-password'
db = 'your-database-name'
# Attempt to connect to the database
try:
connection = pymysql.connect(
host=host,
user=user,
password=password,
database=db
)
print("Connected to the database successfully.")
# Close the connection
connection.close()
print("Database connection closed.")
except pymysql.MySQLError as e:
print(f"Error connecting to the database: {e}")
# Run the test
test_db_connection()
发布者:luotuoemo,转转请注明出处:https://www.jintuiyun.com/192664.html