Home >Backend Development >PHP Problem >What does transaction mean in php

What does transaction mean in php

WBOY
WBOYOriginal
2022-03-23 19:07:382911browse

In PHP, a transaction is a set of atomic SQL queries, or an independent unit of work; a transaction is a logical unit of work for PHP to operate the database. All modifications to the database are either executed or not executed at all. ;Transactions have four characteristics: atomicity, consistency, isolation and durability.

What does transaction mean in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What does transaction mean in php

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

A transaction is a strict series of operations in an application, all operations must complete successfully, otherwise all changes made in each operation will be undone. That is to say, transactions are atomic, and a series of operations in a transaction either all succeed or none of them are performed.

There are two ways to end a transaction. When all steps in the transaction are successfully executed, the transaction is committed. If one of the steps fails, a rollback operation occurs, undoing all operations up to the beginning of the transaction.

Four major characteristics of PHP transactions

Atomicity:

A transaction is a logical unit of work in a database, and all or none of its modifications to the database are 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.

Recommended learning: "PHP Video Tutorial"

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

Statement:
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