1

我正在使用 PyMySQL 和 Python 来访问我的数据库。(MySQLdb 尚不能用于较新版本的 Python。)

这是我的查询:

cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")

但是,不是返回 ,而是返回ingredientID一个布尔值,说明找到了配方。我在 PHP 中使用过 MySQL(i),过去没有出现过这个问题。

4

1 回答 1

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
于 2014-03-31T17:01:08.837 回答