nickzuck_007 icon

Mysql Client Connector

nickzuck_007 | PRO | 01/21/20 09:49:46 AM UTC | 0 ⭐ | 370 👁️ | Never ⏰ | []
Python |

790 B

|

None

|

0 👍

/

0 👎

import MySQLdb
 
class DB:
    def __init__(self, db_config) :
        self.username = db_config["username"]
        self.password = db_config["password"]
        self.db = db_config["database"]
        self.host = '127.0.0.1'
        self.port = 3306
        if "host" in db_config:
            self.host = db_config["host"]
        if "port" in db_config:
            self.port = db_config["port"]
 
    def connect(self) : 
        self.connection = MySQLdb.connect(
                host = self.host,
                user = self.username,
                passwd = self.password,
                db = self.db,
                port = self.port
            )
        self.cursor = self.connection.cursor()
        self.dict_cursor = self.connection.cursor(MySQLdb.cursors.DictCursor)

Comments