#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import sys,time, datetime
class OperateDbTool(object):
@staticmethod
def ConnectToDb(host_info):
con = None
host_info_list = host_info.split(',')
if len(host_info_list) == 5:
con = mdb.connect(host=host_info_list[0].strip(), port=int(host_info_list[1].strip()), \
user=host_info_list[2].strip(),\
passwd=host_info_list[3].strip(), db=host_info_list[4].strip())
return con
@staticmethod
def ExecutiveDb(con, sql):
rt = None
if con != None:
try:
cur = con.cursor()
cur.execute(sql)
data = cur.fetchone()
#print "data: ", data
return data
except mdb.Error, e:
#print "mdb error: %d: %s" % (e.args[0], e.args[1])
pass
finally:
if con:
con.close()
@staticmethod
def CheckBuyofferRunning(host_info):
con = OperateDbTool.ConnectToDb(host_info)
sql = 'SELECT * FROM table_name WHERE e_info)'
data = OperateDbTool.ExecutiveDb(con, sql)