使用新購買的RaspberryPi,我對Python/MySQL非常陌生,所以請原諒我發佈的天真問題。 我已經看過很多Q & A,但我似乎無法理解'爲什麼'這是失敗的。我得到錯誤:「必須是字符串或只讀緩衝區,而不是元組」。如果我用TYPE測試它,我的變量顯示爲一個字符串,所以現在我迷路了。將字符串變量傳遞給MySQL,失敗爲元組
import MySQLdb
import time
db = MySQLdb.connect(host="localhost", user="user",passwd="easypwd", db="imagepi")
cursor = db.cursor()
current_time = time.strftime("%H:%M:%S")
current_date = time.strftime("%Y-%m-%d")
filename = (current_time+'.jpg')
sql = ("""INSERT INTO imagelocator(batch, date, time, filename) VALUES
('1001', current_date, current_time, %s)""", filename)
cursor.execute(sql)
db.commit()
db.close()
非常感謝您爲我提供了一個正確的方向。
我很欣賞你的快速反應。讓我重新閱讀幾遍,並查看您提供的鏈接。我相信這會使我走上正確的道路。謝謝! – generatorlabs
總是樂於提供幫助。 – haliphax