-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconnection.py
More file actions
27 lines (21 loc) · 705 Bytes
/
Copy pathconnection.py
File metadata and controls
27 lines (21 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import mysql.connector
class Connection:
_instance = None
def __new__(cls, *args, **kwargs):
try:
if not cls._instance:
cls._instance = super().__new__(cls)
cls._instance.cnx = mysql.connector.connect(
user='root',
password='9321985498',
host='localhost',
port='3306',
database='banking_sys'
)
return cls._instance
except mysql.connector.Error as e:
print("Connection failed", e)
def get_connection(self):
return self.cnx
if __name__ == "__main__":
connection = Connection()