Home >Backend Development >PHP Tutorial >求助:php获取事务是否成功问题

求助:php获取事务是否成功问题

WBOY
WBOYOriginal
2016-06-02 11:27:381263browse

php事务

ezql php新手
事务怎么捕捉操作数据库出错
多条语句操作数据库 全部成功执行才提交事务 否则回滚
比如 insert 一句成功执行
update 语句执行无错,但更新影响到的记录为0,此时是不要回滚的

如下,$uname 值与数据库中 uname 值相同
$res 就返回0 事务失败

<code>$db->query("BEGIN");$sql="update member set uname=$uname where id=$id";$res=$db->query($sql); if($res){      $db->query("COMMIT");      errAlert("成功","list.php");}else{      $db->query("ROLLBACK");      errAlert("失败,发生错误",$theUrl);}    $db->query("END");</code>
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