what is php transaction

王林
Release: 2023-02-24 14:22:02
Original
4488 people have browsed it

what is php transaction

Four major features of PHP transactions

A transaction is a set of atomic SQL queries, or an independent unit of work.

Atomicity (Atomicity):

A transaction is the logical unit of work of the database. All modifications to the database are either executed or not executed.

Consistemcy:

Before and after the transaction, the state of the database satisfies all integrity constraints.

Isolation:

Concurrently executed transactions are isolated, and one does not affect the other. If there are two transactions, running at the same time, performing the same function, transaction isolation will ensure that each transaction in the system thinks that only that transaction is using the system. This property is sometimes called serialization. To prevent confusion between transaction operations, requests must be serialized or deserialized so that there is only one request for the same data at the same time.

By setting the isolation level of the database, different isolation effects can be achieved.

Persistence (Durability):

After the transaction is completed, the changes made to the database by the transaction are permanently saved in the database and will not be rollback.

Concurrency issues of PHP transactions

1. Dirty reading

Transaction A reads the data updated by transaction B, Then B rolls back the operation, and the data read by A is dirty data.

2. Non-repeatable reading

Transaction A reads the same data multiple times, and transaction B updates the data during the multiple reads of transaction A. And commit, resulting in inconsistent results when transaction A reads the same data multiple times.

3. Phantom reading

System administrator A changed the grades of all students in the database from specific scores to ABCDE grades, but system administrator B changed the grades at this time A record with a specific score was inserted. When system administrator A completed the change, he found that there was still another record that had not been changed. It was like an hallucination. This is called phantom reading.

Summary: Non-repeatable reading and phantom reading are easily confused. Non-repeatable reading focuses on modification, while phantom reading focuses on adding or deleting. To solve the problem of non-repeatable reading, you only need to lock the rows that meet the conditions, and to solve the problem of phantom reading, you need to lock the table.

Recommended tutorial: PHP video tutorial

The above is the detailed content of what is php transaction. For more information, please follow other related articles on the PHP Chinese website!

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