You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
731 B
26 lines
731 B
import os |
|
import mysql.connector |
|
|
|
|
|
def get_db_connection(): |
|
host = os.getenv("OTB_BILLING_DB_HOST", "127.0.0.1") |
|
port = int(os.getenv("OTB_BILLING_DB_PORT", "3306")) |
|
database = os.getenv("OTB_BILLING_DB_NAME", "otb_billing") |
|
user = os.getenv("OTB_BILLING_DB_USER", "otb_billing") |
|
password = os.getenv("OTB_BILLING_DB_PASSWORD", "") |
|
unix_socket = os.getenv("OTB_BILLING_DB_SOCKET", "").strip() |
|
|
|
kwargs = { |
|
"database": database, |
|
"user": user, |
|
"password": password, |
|
"autocommit": False, |
|
} |
|
|
|
if unix_socket: |
|
kwargs["unix_socket"] = unix_socket |
|
else: |
|
kwargs["host"] = host |
|
kwargs["port"] = port |
|
|
|
return mysql.connector.connect(**kwargs)
|
|
|