You need to somehow fetch the result of the query:
cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")
print(cur.fetchone()) # Fetch one row
or
print(cur.fetchall()) # Fetch all rows
Question
I am using PyMySQL with Python to access my database. (MySQLdb is not yet available for newer releases of Python.)
This is my query:
cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")
However, instead of returning the ingredientID
, a boolean is returned stating the recipe was found. I have worked with MySQL(i) in PHP and have not had this issue occur in the past.
Solution
You need to somehow fetch the result of the query:
cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")
print(cur.fetchone()) # Fetch one row
or
print(cur.fetchall()) # Fetch all rows