1

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.

vaultah
  • 44,105
  • 12
  • 114
  • 143
Yehuda Gutstein
  • 381
  • 10
  • 27
  • If by "boolean" you mean "byte literal" then this may help you: http://stackoverflow.com/questions/27855037/pymysql-connection-select-query-and-fetchall-return-tuple-that-has-byte-literals/27873654#27873654 – Michael D. Jan 10 '15 at 07:14

1 Answers1

3

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
vaultah
  • 44,105
  • 12
  • 114
  • 143