示例#1
0
    def __init__(self, host='localhost', user='', passwd='', db=None, port=3306,
                 unix_socket=None, charset='', client_flag=0, cursorclass=Cursor,
                 connect_timeout=None):
        self.charset = 'utf8'
        self.charset_number = 33 # 'utf8'
        self.cursorclass = cursorclass

        self.username = user.encode(self.charset)
        self.password = passwd.encode(self.charset)
        self.db = db and db.encode(self.charset) or None
        
        self.client_flag = client_flag
        self.client_flag |= client.CLIENT_CAPABILITIES
        self.client_flag |= client.CLIENT_MULTI_STATEMENTS
        if db is not None:
            self.client_flag |= client.CLIENT_CONNECT_WITH_DB

        self.transport = Transport(host, port, unix_socket)
        self.transport.connect(connect_timeout, callback=self._handshake)