当前位置:网站首页>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 .
边栏推荐
- Sizeof, strlen find character length
- Install cuda+cusp environment and create the first helloword starter project
- 17. how to understand multi version concurrency control and read / write sets of fabric smart contracts? (vernacular version)
- 实践出真知--你的字节对齐和堆栈认知可能是错误的
- Unity exit Editor Mode
- Common shell script development specifications
- How to use annotations in word
- 适合生鲜批发行业的几种精准接单方式
- ERP 基础数据 概念
- 生鲜配送分拣管理系统哪家比较强?
猜你喜欢
HCIP_ Static experiment
Dfinity (ICP) identity authentication and ledger quick start-3
Recognition of COVID-19 based on paddlepaddle
基于paddlepaddle的新冠肺炎识别
[game theory complete information static game] Application of Nash equilibrium
Disk C is full? A few simple tips teach you to release and clean up tens of gigabytes of space on the C disk, the most effective way to clean up the C disk
【博弈论-完全信息静态博弈】 Nash均衡
Win10系统如何修改桌面路径
母婴用品批发行业使用管理软件提高效率 实现降本增效
CCNP_ Bt- Reissue
随机推荐
Basic operation of dfinity (ICP) development-4
Why do wholesalers use the order system
Bidirectional retransmission step experiment
Edge browser uses bdtab new tab plug-in (BD new tab)
第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
Document contains question type
Altium Designer中导入和导出设置的方法
es6删除对象的某个属性
杨氏矩阵查找数字是否存在
Introduction to dfinity (ICP) -1
学习记录4: einops // cudnn.benchamark=true // hook
MySQL summary
免费文件服务器储存技术
How to efficiently manage commodities and inventory in the beverage wholesale industry
Daffodil upgrade (self idempotent)
使用kvm创建三台能通局域网的虚拟机
Dfinity (ICP) identity authentication and ledger quick start-3
CCNP_ Bt-ospf big experiment (1)
【PYTORCH】RuntimeError: one of the variables needed for gradient computation has been
HCIP_ Static experiment