Home  >  Article  >  Backend Development  >  ThinkPHP implements transaction rollback sample code_PHP tutorial

ThinkPHP implements transaction rollback sample code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:12816browse

ThinkPHP’s transaction rollback example is as follows:

$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();//不成功,则回滚
}

Note: MySQL database must be Innodb and Bdb to support transactions.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825525.htmlTechArticleThinkPHP transaction rollback example is as follows: $m=D('YourModel');//or M( );$m2=D('YouModel2');$m-startTrans();//Just enable it in the first model, or the second one too $result=...
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