[Help] Problems encountered when php writes data to mysql

WBOY
Release: 2016-08-04 09:20:55
Original
882 people have browsed it

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?

Reply content:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template