0

I think i have a problem with my database. Within my python code, i am able to create, drop and select data from my table, but i cannot insert any data.

My execute function

dbhandler.py

    def execute(self, sql):
        self.connection()
        self.cur.execute(sql)
        print(sql)
        self.disconnect()
dataanalysis.py

mysqldb.execute("""CREATE TABLE DATA(p1 int NOT NULL, p2 int NOT NULL);""")
-- Works fine --

mysqldb.execute("""INSERT INTO DATA(p1,p2) VALUES(1,2);""")
-- Nothing happens --

When i connect to my adminer, i can see the table just fine, but no data is inserted. If i run the query within adminer, the data is inserted into the table as intended.

MortenAbra
  • 27
  • 6
  • 1
    Try committing your transaction. You'll need to run something like `mysqldb.commit()`, or some equivalent, based on what driver you are using. – chris.mclennon Jan 09 '20 at 11:53

1 Answers1

1

In order to reflect the change in the table you need to run the commit() function

ConnName.commit()
Vaibhav Jadhav
  • 2,020
  • 1
  • 7
  • 20