标签:对象 commit cursor main 数据 ext t_sql 数据库 update
from pymysql import * def main(): # 创建Connextion连接 conn = connect(host=‘localhost‘, port=3306, user=‘root‘, password=‘‘, database=‘test‘, charset=‘utf8‘) # 获取Cursor对象 cursor = conn.cursor() insert_sql = "insert into users values(0, ‘王五‘,‘女‘, 18)" update_sql = "update users set sex = ‘男‘ where username= ‘王五‘" delete_sql = "delete from users where username=‘王五‘" cursor.execute(insert_sql) # cursor.execute(update_sql) # cursor.execute(delete_sql) # 如果没有提交,数据库的id也会自动增长,只是数据不存在 conn.commit() # 回滚操作 conn.rollback() if __name__ == ‘__main__‘: main()
标签:对象 commit cursor main 数据 ext t_sql 数据库 update
原文地址:https://www.cnblogs.com/f-rt/p/11144612.html