When executing the following:
import pymysql
db = pymysql.connect(host='localhost', port=3306, user='root')
cur = db.cursor()
print(cur.execute("SELECT ParentGuardianID FROM ParentGuardianInformation WHERE UserID ='" + UserID + "'"))
The output is1
How could I alter the code so that the actual value of the ParentGuardianID (which is '001') is printed as opposed to 1
.
I'm sure the answer is simple but I am a beginner so any help would be much appreciated - thanks!
cur.execute()
just returns the number of rows affected. You should do cur.fetchone()
to get the actual result, or cur.fetchall()
if you are expecting multiple rows.