engine = create_engine ("mysql+pymysql://root:111@localhost/xxx", encoding="utf-8", echo=True)
Session_class = sessionmaker (bind=engine)
Session = Session_class ()
modify a record
user = Session.query (User). Filter_by (id=1). First ()
user.name = "aa_changed"
insert a record
user2 = User (name="bb", password="111")
Session.add (user2)
experiment 1:
neither submit nor query. I went to the database to check that there was no change
Lab 2:
does not submit, but I did a query operation. I didn"t expect to write it to the database!
Session.query (User). Filter (User.name.like ("zx*")). First ()
Session.query (User). Filter (User.name = =" zhl"). First ()
) this is it. I would like to ask: why can I modify the database with "only query but no submission"?