nickzuck_007

Mysql Client Connector

Jan 21st, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import MySQLdb
  2.  
  3. class DB:
  4.     def __init__(self, db_config) :
  5.         self.username = db_config["username"]
  6.         self.password = db_config["password"]
  7.         self.db = db_config["database"]
  8.         self.host = '127.0.0.1'
  9.         self.port = 3306
  10.         if "host" in db_config:
  11.             self.host = db_config["host"]
  12.         if "port" in db_config:
  13.             self.port = db_config["port"]
  14.  
  15.     def connect(self) :
  16.         self.connection = MySQLdb.connect(
  17.                 host = self.host,
  18.                 user = self.username,
  19.                 passwd = self.password,
  20.                 db = self.db,
  21.                 port = self.port
  22.             )
  23.         self.cursor = self.connection.cursor()
  24.         self.dict_cursor = self.connection.cursor(MySQLdb.cursors.DictCursor)
Advertisement
Add Comment
Please, Sign In to add comment