mysql - 关于PHP提交数据库事务模式的设计
个人对于事务接触不多,但其实事务对于一个项目而言是比较重要的一个环节,就事务模式拿出来想和大家讨论,更多的是基于该项讨论可以学习更多的事务处理方式。
以Mysql为例:
执行一次一次事务模式,需要关闭MYSQL自动提交模式,然后依次的提交SQL,如果都通过则返回成功和相关的处理。
不知道大家一般是如何设计的?
可以具体到代码逻辑的步骤和场景应用的介绍!
回复内容:
个人对于事务接触不多,但其实事务对于一个项目而言是比较重要的一个环节,就事务模式拿出来想和大家讨论,更多的是基于该项讨论可以学习更多的事务处理方式。
以Mysql为例:
执行一次一次事务模式,需要关闭MYSQL自动提交模式,然后依次的提交SQL,如果都通过则返回成功和相关的处理。
不知道大家一般是如何设计的?
可以具体到代码逻辑的步骤和场景应用的介绍!
这个很简单啊,事物操作一般是操作2个以及以上的多表操作,如果其中一个表的SQL执行失败,则全部SQL执行撤销,也就是事物回滚到原始状态,银行的转账操作肯定是事物,张三将100元打给李四,张三的账户-100元,李四的账户+100元,如果张三操作-100失败,那么李四的+100也就失败了,如果不用事物,要不张三爽死了,要么银行亏死了。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The page is blank after PHP connects to MySQL, and the reason why die() function fails. When learning the connection between PHP and MySQL database, you often encounter some confusing things...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

How to share the same page on the PC and mobile side and handle cache issues? In the nginx php mysql environment built using the Baota background, how to make the PC side and...

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness
