0

I run a program that adds reasonably simple records to a mariaDB database table. Ever since I added the following piece of code:

connection.autocommit = True

The new data I add is no longer visible in phpymadmin. I can still interact with said data through the program however the record count never increases in Phpmyadmin and I cannot find the data in it. The old data is also still there.

I used autocommit because I thought it was a function to bypass the need to go through the process of manually committing every query separately in my code but perhaps it does more than I realize.

Is there a way to display the new records in Phpmyadmin so I can interact with them again?

Edit:

I have come to realize that

connection.autocommit = True

is the correct code but I was trying to perform it on the cursor, not the connection. for anyone reading this make sure you Don't try to set cursor.autocommit to True.

bucketman
  • 463
  • 6
  • 15

1 Answers1

0

You want connection.autocommit(True) for autocommit.

Or, specify it when you create your connection.

The behavior you describe is what happens when you don't commit.

If you don't want to use autocommit you can do this after a bunch of INSERT / UPDATE / DELETE operations to commit them: connection.commit() Then, other MySQL connections, like your phpmyadmin, will be able to see the new data.

Or if you decide you don't want to commit your operations you can do connection.rollback() .

In Python's MySQL API, autocommit is turned off unless you turn it on.

Notice that the uncommitted data is not stored in your program as you put it. It's in MySQL, and visible to the connection that put it there. It just isn't visible to other MySQL connections.

Please study this: https://dev.mysql.com/doc/refman/8.0/en/commit.html It will help you understand what's going on. The point is to allow you to change several rows in the database so they all appear to change at once to other programs.

O. Jones
  • 103,626
  • 17
  • 118
  • 172