简体   繁体   English

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:我已成功连接到 python 中的数据库,但它没有保存我提供的数据。这是代码:

    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:它可以成功打印句子、final_result 和 time 但不能将它们保存在 database.sentence、final_result 和 time 少于 50 个字符。我在 mysql 中手动创建了数据库,其中包含以下行:

id -> auto_increment,pk
main_status -> varchar(255)
extracted_info -> varchar(255)
seen  -> int(10),Null=True
time ->varchar(255)
connection.commit()

在cursor.execute之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM