感兴趣python
调用MysqL连接示例的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。<br>
# *** 网 (jb51.cc) ***
import MysqLdb
db_config = {
'host': '120.55.189.188','user': 'datahouse','passwd': 'DTHS2016','port': 3306,'db': 'logdata','charset': 'utf8'
}
def getDB():
try:
conn = MysqLdb.connect(host=db_config['host'],user=db_config['user'],passwd=db_config['passwd'],port=db_config['port'],charset=db_config['charset'])
conn.autocommit(True)
curr = conn.cursor()
curr.execute("SET NAMES utf8");
curr.execute("USE %s" % db_config['db']);
return conn,curr
except MysqLdb.Error,e:
print "MysqL Error %d: %s" % (e.args[0],e.args[1])
return None,None
# *** 网 (jb51.cc) ***