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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
