[SOLVED] Store number of rows in mysql data in variable

Issue

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

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

Solution

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);

Answered By – Umair Mubeen

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published.