I am new to Python-Flask and am trying to use MySQLDB to conenct to the database. However, I am unable to determine how to check if the query executed by the cursor is successful or if it failed. In the code below, can someone please advise how I can go about the condition in the if statement? c is a cursor to a database and it is connecting successfully, so I excluded it from the code below.
qry = "SELECT count(*) FROM users where username = (%s)" % (username)
try:
x = c.execute(qry) #Is this correct? Doe execute command return a value?
if <<*Check if the query executed successfully*>>:
return 'Success'
else:
return 'Failure'
except Exception as e:
return 'Failure'