48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
import mariadb
|
|
import sys
|
|
|
|
# # Database connection parameters
|
|
# host = "127.0.0.1" # host = "localhost" # or the IP of the machine if accessed remotely
|
|
# port = 3306
|
|
# user = "root"
|
|
# password = "my-secret-pw" # Update with your password
|
|
# database = "mydatabase" # Replace with your actual database name
|
|
|
|
db_config = {
|
|
'user': 'dbUser',
|
|
'password': 'dbPassword',
|
|
'host': '127.0.0.1', # 'host': 'localhost',
|
|
'database': 'projectGeislinger',
|
|
'port': 3306 # Standard port for MariaDB
|
|
}
|
|
|
|
try:
|
|
# Establish a connection
|
|
# conn = mariadb.connect(
|
|
# user=user,
|
|
# password=password,
|
|
# host=host,
|
|
# port=port,
|
|
# database=database
|
|
# )
|
|
|
|
conn = mariadb.connect(**db_config)
|
|
|
|
print("Connection successful!")
|
|
|
|
# Create a cursor object
|
|
cur = conn.cursor()
|
|
|
|
# Example query
|
|
cur.execute("SELECT VERSION()")
|
|
result = cur.fetchone()
|
|
print(f"MariaDB version: {result[0]}")
|
|
|
|
except mariadb.Error as e:
|
|
print(f"Error connecting to MariaDB: {e}")
|
|
sys.exit(1)
|
|
|
|
finally:
|
|
if conn:
|
|
conn.close()
|