Home > Article > Backend Development > [Help] Problems encountered when php writes data to mysql
There is a requirement in the php project to write data to two tables at the same time!
If you write two sql statements directly in the controller, it is possible that the sql of table A is executed, and the sql of table B is not executed.
How to solve such a problem?
Another question is, because the sql of table A has been executed, and the sql of table B has not been executed, can the data of table A be rolled back from MySQL to the time when it was not added?
There is a requirement in the php project to write data to two tables at the same time!
If you write two sql statements directly in the controller, it is possible that the sql of table A is executed, and the sql of table B is not executed.
How to solve such a problem?
Another question is, because the sql of table A has been executed, and the sql of table B has not been executed, can the data of table A be rolled back from MySQL to the time when it was not added?
Just use transaction processing
Excuse me, are the structures of table a and table b the same?
Triggers, you can also use transaction rollback
To use transactions, the database must support innodb