我使用PyMySQL和Python来访问我的数据库。(MySQLdb还不能用于较新版本的Python。)
这是我的疑问:
cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")但是,不返回ingredientID,而是返回一个布尔值,说明找到了菜谱。我在PHP中使用过MySQL(i),过去没有发生过这个问题。
发布于 2014-03-31 17:01:08
您需要以某种方式获取查询的结果:
cur = db.cursor()
cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions")
print(cur.fetchone()) # Fetch one row或
print(cur.fetchall()) # Fetch all rowshttps://stackoverflow.com/questions/22767603
复制相似问题