forked from KovidReddy/MWDB_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresDB.py
More file actions
22 lines (18 loc) · 741 Bytes
/
PostgresDB.py
File metadata and controls
22 lines (18 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import psycopg2
class PostgresDB:
def __init__(self, password, host='localhost', database='postgres', user='postgres', port=5432):
self.host = host
self.database = database
self.user = user
self.port = port
self.password = password
def connect(self):
conn = None
try:
# connect to the PostgreSQL server
print('Connecting to the PostgreSQL database...')
conn = psycopg2.connect(host=self.host, database=self.database,
user=self.user, password=self.password, port=self.port)
except (Exception, psycopg2.DatabaseError) as error:
print(error)
return conn