Python 3.5:无法从MySQL数据库获取所有字段

时间:2017-03-09 18:10:05

标签: mysql python-3.5 pymysql

我有一个SQL数据库,里面有两个食谱,我希望能够以字符串的格式将所有这些食谱带出数据库。我目前的代码只需要一个。

def connector():
    # Connects to the SQL serevr
    connection = pymysql.connect(host='localhost',
                                 user='HarryMiddlemas',
                                 password='qwer',
                                 db='project_schema',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)
    return connection

    def myRecipes():
        connection = connector()
        try:
            with connection.cursor(pymysql.cursors.DictCursor) as cursor:
                sql = "SELECT `recipe_name`, `recipe_ingredients`,`recipe_method` FROM `recipes` WHERE `user_id`=%s"
                cursor.execute(sql, (currentUser))
                result = cursor.fetchall()
                recipeResults = result
                print(recipeResults)
        finally:
            connection.close()

有谁知道我哪里出错了?

0 个答案:

没有答案