尝试执行以下操作时:
def postToMySQL(date,data,date_column_name,data_column_name,table):
cursor = conn.cursor ()
sql = "\"\"\"INSERT INTO " + table + " (" + date_column_name + ", " + data_column_name + ") VALUES(%s, %s)" + "\"\"\"" #+ ", " + "(" + date + ", " + data + ")"
cursor.execute(sql,(date,data))
我收到此错误:
_mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax... near: \' """INSERT INTO natgas (Date, UK) VALUES(\'2012-05-01 13:00:34\' , \'59.900\')""" \'在第 1 行')
我对语法错误的地方感到困惑,因为以下硬编码示例可以正常工作:
def postUKnatgastoMySQL(date, UKnatgas):
cursor = conn.cursor ()
cursor.execute("""INSERT INTO natgas (Date, UK)VALUES(%s, %s)""", (date, UKnatgas))
你能发现错误吗?
或者,您能告诉我如何将参数传递给字段列表和值列表吗?
非常感谢!