'How to properly count rows from mysql using python?

I am trying to get rows quantity from query using python to mysql. I've been using rowcount but returned value is always 0.

def getLastData(md5TwitterDate):
    conectar = connection()
    try:
        cursor = conectar.cursor()
        query = "SELECT fecha,numeroreporte,internoid FROM jsywe_ncnsismos_sismosigp WHERE internoid = '%s' and published=1"
        cursor.execute(query, md5TwitterDate)
        lastEvent = cursor.fetchall()
        rowsa = cursor.rowcount
    except Error as ex:
        print("Error to get data: ", ex)
    finally:
        if conectar.is_connected():
            conectar.close()
    #return False if rowsa> 0 else True
    return rowsa

Also tried this way setting a variable to cursor.execute but in this case always get none

def getLastData(md5TwitterDate):
    conectar = connection()
    try:
        cursor = conectar.cursor()
        query = "SELECT fecha,numeroreporte,internoid FROM jsywe_ncnsismos_sismosigp WHERE internoid = '%s' and published=1"
        rowsa = cursor.execute(query, md5TwitterDate)
        lastEvent = cursor.fetchall()
    except Error as ex:
        print("Error to get data: ", ex)
    finally:
        if conectar.is_connected():
            conectar.close()
    #return False if filas > 0 else True
    return rowsa

Tested query on database and it works, it returns 1 row



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source