带有变量列的Python2.7 + MySQL查询返回变量值

时间:2016-06-23 12:44:53

标签: python mysql

我尝试发送此查询:

    data = ('name')
    query = ("SELECT %s FROM table")

    cursor.execute(query,[data])

并打印int:

b = cursor.fetchall()
    for row in b:
        a = row[0]
        list_of_a.append(model)
    return list_of_a

    print list_of_a

并获得:

名 名称 名称 名称 名称 名称 名称 名称 名称 名称 名称 名称 名称 名称 名称

我尝试制作query ("SELECT name FROM table")

我得到:value1,value2,value3 ....等等来自列"名称"

1 个答案:

答案 0 :(得分:0)

像这样更改您的查询。

query = ("SELECT '%s' FROM table")

它会起作用。

相关问题