python2.7 使用MySQLdb模块封装一个获取mysql连接的类案例
2017-02-09 15:51
633 查看
案例具体如下:
import MySQLdb
class GetMysql(object):
def getCon(self):
Host="192.168.0.222"
Port=3306
User="root"
Passwd="111111"
Db="redmine"
try:
self.db=MySQLdb.connect(host=Host,user=User,Passwd=Passwd,db=Db,port=Port,charset='utf8')
except Exception as e:
print "Get Mysql Database Error!",('%s' % e)
return self.db
def closeCon(self):
try:
self.db.close()
except TypeError:
print "Close Mysql Database Error!",('%s' % e)
import MySQLdb
class GetMysql(object):
def getCon(self):
Host="192.168.0.222"
Port=3306
User="root"
Passwd="111111"
Db="redmine"
try:
self.db=MySQLdb.connect(host=Host,user=User,Passwd=Passwd,db=Db,port=Port,charset='utf8')
except Exception as e:
print "Get Mysql Database Error!",('%s' % e)
return self.db
def closeCon(self):
try:
self.db.close()
except TypeError:
print "Close Mysql Database Error!",('%s' % e)
相关文章推荐
- Python算法之---冒泡,选择,插入排序算法
- Python生成动态字符画
- 列表与元组——索引
- 数字与表达式——函数汇总
- 数字与表达式——长字符串、原始字符串和Unicode
- numpy学习笔记(2)
- Python安装Twisted框架并使用
- 数字与表达式——input与raw_input
- 数字与表达式——字符串
- 数字与表达式——变量、函数、模块
- 数字与表达式——长整型数
- python的数字与表达式——浮点数
- python在andriod上运行
- python基础教程-数字与表达式——浮点数
- [转]Resolving Python error: Unable to find vcvarsall.bat
- python外部调用程序
- redmine中使用python按人员分组统计问题入excel的自编写案例
- python控制windows剪贴板,向剪贴板中写入图片
- [Python编程实战] 第一章 python的创建型设计模式1.1抽象工厂模式
- pythonzip()函数的使用