pdo提交事务 数据库连接成功.ATUOCOMMIT修改为0后$stmt返回0

<?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
浏览 1456回答 1
1回答

幕布斯7510621

我知道了 是因为含中文  我没有 $pdo->exec('set names utf8');
打开App,查看更多内容
随时随地看视频慕课网APP