gpt4 book ai didi

python - SQL 插入不起作用(没有出现错误)

转载 作者:行者123 更新时间:2023-11-28 23:31:32 26 4
gpt4 key购买 nike

您好,我正在通过 Python 函数创建查询。

当我尝试插入某些值时:出现成功插入,但当我手动搜索数据库时我的查询没有出现。

代码是这样的:

@post('/store_artist')
def store_artist():
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='songs')
c = conn.cursor();
c.execute("SET NAMES 'utf8'");
c.execute("SET CHARACTER SET 'utf8'");
artist_name = request.forms.get('artist_name')
artist_surname = request.forms.get('artist_surname')
artist_bday = request.forms.get('artist_bday')
artist_id = request.forms.get('artist_id')
c.execute(("INSERT INTO kalitexnis (ar_taut,onoma,epitheto, etos_gen) VALUES (%s, %s, %s, %s)"),(int(artist_id),artist_name,artist_surname,int(artist_bday)))
result = c.fetchall()
return "Artist info successfully stored"

有什么想法吗?谢谢

最佳答案

您必须在每次insertupdate 查询之后调用conn.commit() 以将更改保存到数据库中。

或者,您可以调用 conn.autocommit(True),然后更改将立即保存在数据库中。

关于python - SQL 插入不起作用(没有出现错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37167650/

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