Вопрос

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.

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top