<?php
header('content-type:text/html;charset=utf-8');
$pdo=new PDO('mysql:host=localhost;dbname=user2','root','');
$pdo->exec('set names utf8');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
try{
$sql="insert into t5(name,num) values('好的','88')";
$smt=$pdo->prepare($sql);
$smt->execute();
$sql="insert into t5l(name,num) values('对的','66')";
$smt=$pdo->prepare($sql);
$smt->execute();
$pdo->commit(); //无错误提交
}catch(PDOException $e){
$pdo->rollBack(); //有错误撤销
};
?>
网友评论