# 解释器python 3.7 C:\ProgramData\Anaconda3\python.exe
db = pymysql.connect("IP","user","password","database")
cursor = db.cursor()
time = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
sql = """INSERT INTO zigbee(pressure,pressure_flag,vibrance,vibrance_flag,temperature,temperature_flag,time) VALUES (%s,%s,%s,%s,%s,%s,'%s')"""% \
(pressure, pressure_flag, vibrance, vibrance_flag, temperature, temperature_flag, time )
cursor.execute(sql)
db.commit()
本次在调试过程中,无法正常将time插入到数据库中。
发现,在sql的insert语句中,将time对应的%s,加上引号,即可插入。(与语句time = datetime.now().strftime("%Y-%m-%d %H-%M-%S")有关)。