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.

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top