2023-12-28 13:38:21 +01:00

18 lines
422 B
Python

#!/usr/bin/python
import psycopg2
def connect_db(db_settings):
conn = None
print("Connecting to the PostgreSQL database...")
try:
conn = psycopg2.connect(**db_settings)
print("Connection success")
except (Exception, psycopg2.DatabaseError) as error:
print(error)
return conn
def close_db(conn):
if conn is not None:
conn.close()
print("Connection closed")