def get_user(self, ID): connection = pymysql.connect(host=db.db_host, port=db.db_port, user=db.db_user, passwd=db.db_passwd, db=db.db_name) cursor = connection.cursor() SQL = "SELECT * FROM USERS WHERE ID_USER = %s OR PHONE = %s;" SQL = SQL % (str(ID), str(ID)) cursor.execute(SQL) user = User() user.ID = cursor._rows[0][0] user.NICK = cursor._rows[0][1] user.STATUS = cursor._rows[0][2] user.PHONE = cursor._rows[0][3] user.USER_IMAGE = cursor._rows[0][4] user.LAST_RECEIVED_MESSAGE = cursor._rows[0][5] cursor.close() connection.close() return user.serialize()
def get_users(self): connection = pymysql.connect(host=db.db_host, port=db.db_port, user=db.db_user, passwd=db.db_passwd, db=db.db_name) cursor = connection.cursor() cursor.execute("SELECT * FROM USERS") users = list() for row in cursor: user = User() user.ID = row[0] user.NICK = row[1] user.STATUS = row[2] user.PHONE = row[3] user.USER_IMAGE = row[4] user.LAST_RECEIVED_MESSAGE = row[5] users.append(user.serialize()) cursor.close() connection.close() return users