def lookfor(var1,var2):
try:
with connection().cursor() as cursor:
sql = """SELECT * FROM servers WHERE %s = %s"""
cursor.execute(sql, (var1, var2))
result = cursor.fetchall()
for x in result:
print(x)
finally:
connection().close()
lookfor(“优先级”,“重要”)
-
我得到0条结果,没有错误...:(
请帮助,必须有一种方法。
答案 0 :(得分:0)
您可以使用字符串插值:
with connection().cursor() as cursor:
sql = "SELECT * FROM servers WHERE " + str(var1) + " = " + str(var2)
cursor.execute(sql)
result = cursor.fetchall()