#! /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.exe cute (SQL)
Data = cur. fetchone ()
# Print "data:", Data
Return data
Failed t 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)