Home > Backend Development > PHP Tutorial > ThinkPHP实现事务回滚示例代码_PHP

ThinkPHP实现事务回滚示例代码_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 11:51:34
Original
988 people have browsed it

ThinkPHP

ThinkPHP的事务回滚示例如下:

$m=D('YourModel');//或者是M();
$m2=D('YouModel2');
$m->startTrans();//在第一个模型里启用就可以了,或者第二个也行
$result=$m->where('删除条件')->delete();
$result2=m2->where('删除条件')->delete();
if($result && $result2){
$m->commit();//成功则提交
}else{
$m->rollback();//不成功,则回滚
}

Copy after login

注意:MySQL数据库必须是Innodb和Bdb才能支持事务。

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template