0

我一直在关注这个先前的答案,但是我仍然收到语法错误:

堆栈溢出答案

    cursor.execute ("""
   UPDATE tblTableName
   SET Year=%s, Month=%s, Day=%s, Hour=%s, Minute=%s
   WHERE Server=%s
   """, (Year, Month, Day, Hour, Minute, ServerID))

我的代码是:

def postToMySQL(data,fieldname,table,col):
if fieldname == "Year":
    sql = "INSERT INTO " + table + " ("+ fieldname + ") VALUES (%s)"
    c.execute(sql, data)
else:
    c.execute ("""
   UPDATE %s
   SET US=%s
   WHERE ID=%s
    """, (table, data, col))

然后该表如下所示:

堆栈溢出答案

语法错误是:

_mysql_exceptions.ProgrammingError: (1064..near ''OilProvedReservesHistory' SET US = '36.533' WHERE ID=1' at line 1'

你能发现错误吗??谢谢

4

1 回答 1

1

应该是这样的,没有引号

设置我们 = '36.533'

你可以试试这个:

UPDATE %s
   SET US=%s
   WHERE ID=%s
于 2012-05-07T17:20:57.940 回答