Python无法将行插入到MySQL

2024-10-01 07:11:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试完成以下查询:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES (% (ua) s,% (ru) s);"
data = {'ua': 'ukrainian', 'ru': 'russian'}
cursor.execute (sql, data)

执行此查询后,表中没有此类记录。你知道吗

如果在SQLyog中执行相同的查询,则记录将存在。你知道吗

我也试过:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');"
cursor.execute (sql)
print sql

表中没有行。你知道吗

控制台显示:INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');

在SQLyog中执行此查询时,通常会在表中插入一行。你知道吗

我创建了另一个具有相同结构的表。你知道吗

有人能帮我吗?你知道吗


Tags: executesqldataru记录cursoruainsert
1条回答
网友
1楼 · 发布于 2024-10-01 07:11:13

您需要^{}来反映更改。你知道吗

9.2.3. Method MySQLConnection.commit()

This method sends a COMMIT statement to the MySQL server, committing the current transaction. Since by default Connector/Python does not autocommit, it is important to call this method after every transaction that modifies data for tables that use transactional storage engines.

相关问题 更多 >