当前位置:网站首页>Notes on MySQL transaction not automatically submitting
Notes on MySQL transaction not automatically submitting
2022-06-13 08:18:00 【Parthenocissus still works】
Use the company framework to write a php Script , Perform some data insertion updates, etc , The code uses mysql Business , But it's strange that the last data update will not take effect every time I cycle , And this one sql Execution is outside the transaction , And all the transactions were executed successfully , The data also returns success , If the transaction is closed , The last sentence sql It will also be executed successfully . The analytical question should be mysql Business related issues , At first, I thought it was my own code , But check , After testing for a long time, I didn't find , So consider whether it is mysql Environment setting problem , contrast , Modifying the transaction level has not been solved . Finally, the suspicion is that the original framework mysql There's something wrong with the drive . So copy the original driver (mysqli) Code for , Reuse pdo Expand and write a , When the modified procedure is written to the transaction related code , Suddenly thought of , Is it a setting autocommit = 0; As a result of . Because opening a transaction usually puts autocommit Set to 0. This is common sense , Combine the previous knowledge , every last sql In fact, it is a simple matter , So we started the test . The test code is as follows :
<?php
class testcommit extends testAffair
{
private $chance = 5;
public function totest()
{
// self::$db->beginTransaction();
self::$db->setAutocommit(0);// Execute the replacement code for the second time
$data = array(
'type' => 'test',
'email' => '[email protected]',
'code' => rand(0, 255),
'times' => $this->chance,
'ip' => '127.0.0.1',
'createtime' => time()
);
$row = self::$db->insert('testms', $data);
if(!$row){
// echo 'rollbacked' . PHP_EOL;
// self::$db->rollback();
return false;
}
$insertid = self::$db->getInsertid();
var_dump($row, $insertid);
// self::$db->commit();
return $insertid;
}
public function exctest()
{
$result = $this->totest();
if($result){
$res = self::$db->update('goods', array('status' => '0'), array('id' => '123'));
var_dump($res);
echo 'over';
}else{
$res = self::$db->update('goods', array('deleted' => '1'), array('id' => '123'));
echo 'fail';
}
}
}
$test = new testcommit();
$test->exctest();
The annotation code is the code tested for the first time , among beginTransaction Is automatically set in autocommit by 0. and rollback and commit Is not set in . The first test was really testms The data is inserted , But no updates goods surface . The second test commented out the transaction , Only add settings autocommit=0, As expected ,testms Table and goods There are no inserts or updates . Third setting autocommit=1. The results are all successfully executed and the data is successfully submitted and effective .
To solve the last problem , After the transaction is completed, the autocommit Set to 1 that will do .
边栏推荐
- SolidWorks修改工程图中文字字体的方法
- 母婴用品批发行业使用管理软件提高效率 实现降本增效
- CCNP_ BT static routing
- ERP 基础数据 概念
- Founder of Starbucks: no longer open "public toilets" to non store consumers for safety reasons
- 4. fabric2.2 create and join channels (use the official demo)
- Why do wholesalers use the order system
- mysql面试题
- Detailed explanation of digital certificate and Ca
- 2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
猜你喜欢
HCIP_ MGRE experiment
ES6 deleting an attribute of an object
Gtk+ programming example on page 115 - simplest progress bar 2 with steps to write GTK program using anjuta
[pytorch] pytorch0.4.0 installation tutorial and GPU configuration collection (including test code)
汽配行业面临的难题用什么软件帮忙解决呢
23 | adventure and prediction (II): relay race in the assembly line
What software can be used to solve the problems faced by the auto parts industry
Bidirectional retransmission step experiment
生鲜配送分拣管理系统哪家比较强?
ERP基础数据 金蝶
随机推荐
汽配行业面临的难题用什么软件帮忙解决呢
Create a substrate private network
sizeof、strlen求字符长度
Install cuda+cusp environment and create the first helloword starter project
2022 electrician (elementary) examination questions and simulation examination
平面合并(MATLAB)
Overall process analysis of account book operation in fabric0.6
Rust writes near smart contract
mysql面试题
How can the small and medium-sized lighting industry make use of the digital transformation to stand out from the encirclement?
中小型照明灯饰行业如何利用数字化转型突出重围?
Unity exit Editor Mode
Document contains question type
钉钉小程序如何隐藏tab
【博弈论-完全信息静态博弈】 Nash均衡的应用
Shell脚本常用开发规范
适合生鲜批发行业的几种精准接单方式
直播回顾 | 积极防御体系下BAS技术创新探索
Young's matrix to find whether a number exists
Cosmos Starport installation and startup