<?php
$options=array(PDO::ATTR_AUTOCOMMIT,0);
$pdo=new PDO("mysql:host=localhost;dbname=manage","","",$options);
try{
$pdo->beginTransaction();
$sql= "update employee set age=age+500 where name = '王五'";
$stmt1=$pdo->exec($sql);
var_dump($stmt1);
if($stmt1==0){
throw new PDOException('添加失败');
}
$sql2="update employee set age=age-500 where name = '张三三'";
$stmt=$pdo->exec($sql2);
if($stmt==0){
throw new PDOException('减少失败');
}
$pdo->commit();
}catch (PDOException $e){
$pdo->rollBack();
echo $e->getMessage();
}
?>
幕布斯7510621