[phpstudy]php PDO实现的事务回滚示例

更新时间:2021-08-03    来源:word    手机版     字体:

【www.bbyears.com--word】

$servername="localhost";$username="root";$password="admin";$dbname="test";word">try{  $conn=new PDO("mysql:host=$servername;dbname=$dbname",$username,$password);  $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);  //开始事务  $conn->beginTransaction();  $conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','XIAMING','yexianming@163.com')");  $conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','CONG','yecong@163.com')");  $conn->exec("INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('FANG','MENG','fangmeng@168.com')");  //提交事务  $conn->commit();  echo "New records created successfully!";}catch(PDOException $e){   //回滚事务   $conn->rollBack();   echo $sql."
"
.$e->getMessage();}$conn=NULL;

本文来源:http://www.bbyears.com/bangongshuma/133779.html

热门标签

更多>>

本类排行