Search code examples
pythonmysqlmysql-connectoradminer

Python - Insert data to table not working


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.


Solution

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

    ConnName.commit()