gpt4 book ai didi

Python INSERT 不会写入数据库

转载 作者:行者123 更新时间:2023-11-29 05:15:23 25 4
gpt4 key购买 nike

<分区>

所有的数据库名和表名都是正确的。 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))

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com