'Store number of rows in mysql data in variable

SELECT COUNT( *) as "Number of Rows"
FROM orders;

i want to add "Number of rows" into a python variable but idk how.



Solution 1:[1]

stored numbers of rows in python variables

db= MySQLdb.connect("HOSTNAME", "USER_NAME", "PWD", "DB_NAME");
cursor= db.cursor();
number_of_rows = cursor.execute("SELECT COUNT (*) FROM TBL");
print(number_of_rows);

Sources

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

Source: Stack Overflow

Solution Source
Solution 1