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
sqlhandler.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录