當我運行這個函數時發生了一些錯誤,但我不知道出了什么問題。def insertVariblesIntoTable(newepc, newtimestamp): try: connection = mysql.connector.connect(host='localhost', database='myDB', user='root', password='root') cursor = connection.cursor() mySql_insert_query = """INSERT INTO myTB(epc,time_stamp) SELECT newepc,newtimestamp FROM dual WHERE NOT EXISTS (SELECT * FROM myTB WHERE epc=newepc AND time_stamp>NOW()-INTERVAL 1 MINUTE )""" cursor.execute(mySql_insert_query) connection.commit() print("Record inserted successfully into myTB table") except mysql.connector.Error as error: print("Failed to insert into MySQL table {}".format(error)) finally: if (connection.is_connected()): cursor.close() connection.close() # print("MySQL connection is closed")錯誤:無法插入 MySQL 表 1054 (42S22):“字段列表”中的未知列“newepc”
1 回答

瀟瀟雨雨
TA貢獻1833條經驗 獲得超4個贊
據我所知,您正在嘗試訪問一個不存在的名為“newepc”的列。發生這種情況是因為您沒有在選擇查詢中轉義變量“newepc”,mySql 不知道它應該是一個變量。您可以嘗試 f-Strings 或只是正常的連接。
添加回答
舉報
0/150
提交
取消