sqlhandler.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:lightbulb-framework 作者: lightbulb-framework 项目源码 文件源码
def connect(self, db_config):
        """
        Connect to MySQL database
        Args:
            db_config (dict): A dictionary containing the configuration
        Returns:
            (Mysql Connector): The established MySQL connection
        """
        try:
            print 'Connecting to MySQL database:',
            self.conn = MySQLdb.connect(
                host=db_config['host'],
                port=db_config['port'],
                user=db_config['user'],
                passwd=db_config['passwd'],
                db=db_config['db'])
            print 'OK'
            self.conn.autocommit(True)
            self.cursor = self.conn.cursor()
            return self.conn
        except MySQLdb.Error as error:
            print error
            return 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号