标签:
事务处理流程
PDO::beginTransaction
所有的实务操作就是增删改
PDO::commit:成功后提交数据
PDO::rollback:失败后回滚数据
<?php //PDO事务处理 //连接认证 $pdo = new PDO(‘mysql:host=localhost;dbname=project‘,‘root‘,‘root‘); //1. 开启事务 $res = $pdo->beginTransaction(); //var_dump($res); //2. 事务处理(多条SQL语句执行) $sql = "update pro_student set s_age = 28 where s_id = 20"; $lines = $pdo->exec($sql); //var_dump($lines); $sql = "select * from pro_student where s_id = 20"; $stmt = $pdo->query($sql); //var_dump($stmt->fetch(PDO::FETCH_ASSOC)); //3. 提交事务 if($lines){ //更新成功 $pdo->commit(); }else{ //更新失败 echo ‘失败‘; $pdo->rollback(); }
注意
标签:
原文地址:http://www.cnblogs.com/hf8051/p/4672866.html