php事务控制问题

WBOY
Release: 2016-06-06 20:18:38
Original
1484 people have browsed it

php事务控制一定需要这样控制的吗?

if($sql1&& $sql2 && $sql3)
{

<code>$tranDb->commit();</code>
Copy after login
Copy after login

}

这样sql多了,if的条件会很多$sql1&&$sql2,不同的函数之间如何控制事务?

回复内容:

php事务控制一定需要这样控制的吗?

if($sql1&& $sql2 && $sql3)
{

<code>$tranDb->commit();</code>
Copy after login
Copy after login

}

这样sql多了,if的条件会很多$sql1&&$sql2,不同的函数之间如何控制事务?

应该通过捕获异常的方式提交事务或事务回滚。

if (!$sql1){
$db->rollback();
}
if (!$sql2){
$db->rollback();
}
if (!$sql3){
$db->rollback();
}

$db->comit();
就是全部成功后再提交,一有失败就回滚,手机码字,希望能看懂!

楼上的看起来清晰,但冗余也太多了。 题主的写法不错,目前我也是这么写的。

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!