python - python connection is not saving data in database
问题描述
I have connected to database in python successfully but it is not saving the data I provide.Here is the code :
try:
connection = MySQLdb.connect(host="localhost",user="root",passwd="",db="traffic_alert")
except Exception as e:
print('Not connected')
cursor = connection.cursor()
cursor.execute("insert into data (main_status,extracted_info,time) values (%s,%s,%s)",[sentence,final_result,time])
print(sentence)
print(final_result)
print(time)
it can successfully print sentence, final_result and time but not saving them in database.sentence,final_result and time are less than 50 characters.I have created the database manually in mysql with these rows :
id -> auto_increment,pk
main_status -> varchar(255)
extracted_info -> varchar(255)
seen -> int(10),Null=True
time ->varchar(255)
解决方案
connection.commit()
在 cursor.execute 之后
推荐阅读
- javascript - 在Javascript中查找要更改的位数以获得等效的二进制数
- roblox - 房子怎么定位?罗布乐思
- protractor - 如何在分片测试时仅使用量角器和黄瓜生成一份报告?
- sql - 从该表中选择正确数据的有效方法是什么?
- javascript - 如何使用 SWR 对具有嵌套数组的复杂对象进行变异?
- c# - 没有提升权限的 Windows 文件关联
- mysql - 视窗/MySQL 5.5。/ 在异常 0xc0000005 上启动时崩溃
- postgresql - 在 DBeaver 或 PgAdmin 中看不到引发消息
- java - 如何消除spring boot中bean的重复性能?
- node.js - 从猫鼬对象数组中的最后一个元素的(对象)字段中查找