所有数据库名称和表名都是正确的。 python脚本运行没有错误,但值永远不会写入数据库(表保持为空)`
datetimenowDB = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
deviceDB = "ALARM"
statusDB = "Tripped"
typeDB = "None"
try:
db = MySQLdb.connect(
host="localhost",
user="root",
passwd="toor",
db="log_database")
except Exception as e:
sys.exit('Cant get into database.')
c = db.cursor()
c.execute("INSERT INTO control_log (date_time, device, status, type) VALUES (%s,%s,%s,%s)",
(datetimenowDB, deviceDB, statusDB, typeDB))