(self, dbconfig)
u'构造器：根据数据库连接参数，创建MySQL连接
u'构造器：根据数据库连接参数，创建MySQL连接
u 构造器：根据数据库连接参数，创建MySQL连接
def __init__(self, dbconfig):
      u'构造器：根据数据库连接参数，创建MySQL连接'
      try:
        self._conn = MySQLdb.connect(host=dbconfig['host'],
                       port=dbconfig['port'], 
                       user=dbconfig['user'],
                       passwd=dbconfig['passwd'],
                       db=dbconfig['db'],
                       charset=dbconfig['charset'])
      except MySQLdb.Error, e:
        self.error_code = e.args[0]
        error_msg = 'MySQL error! ', e.args[0], e.args[1]
        print error_msg
        
        # 如果没有超过预设超时时间，则再次尝试连接，
        if self._timecount < self._TIMEOUT:
          interval = 5
          self._timecount += interval
          time.sleep(interval)
          return self.__init__(dbconfig)
        else:
          raise Exception(error_msg)
      
      self._cur = self._conn.cursor()
      self._instance = MySQLdb
def __init__ ( self , dbconfig ) : try : self . _conn = MySQLdb . connect ( host = dbconfig [ 'host' ] , port = dbconfig [ 'port' ] , user = dbconfig [ 'user' ] , passwd = dbconfig [ 'passwd' ] , db = dbconfig [ 'db' ] , charset = dbconfig [ 'charset' ] ) except MySQLdb . Error , e : self . error_code = e . args [ 0 ] error_msg = 'MySQL error! ' , e . args [ 0 ] , e . args [ 1 ] print error_msg # 如果没有超过预设超时时间，则再次尝试连接， if self . _timecount < self . _TIMEOUT : interval = 5 self . _timecount += interval time . sleep ( interval ) return self . __init__ ( dbconfig ) else : raise Exception ( error_msg ) self . _cur = self . _conn . cursor ( ) self . _instance = MySQLdb