标签:return err proc color sage new llb cep att
直接上代码:
1 <?php 2 require_once ‘db_const.php‘; 3 require_once ‘helperPub.php‘; 4 5 //测试存储过程的事务 6 //http://localhost/API_WMS/WMS_BatchTest.php 7 8 echo ‘Hello‘ . PHP_EOL; 9 $ret = BatchTest(); 10 11 echo json_encode($ret, JSON_UNESCAPED_UNICODE); 12 13 function BatchTest() 14 { 15 $ret_value = array(); 16 echo ‘1‘ . PHP_EOL; 17 18 $db = new PDO(STR_CONN, DB_USER, DB_PASS); 19 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 20 $db->beginTransaction(); 21 try { 22 23 $sql = ‘execute procedure PROC_S1;‘; 24 $statement = $db->prepare($sql); 25 $ret = $statement->execute(); 26 if(! $ret) 27 { 28 throw new Exception("PROC_S1"); 29 } 30 echo ‘2‘ . PHP_EOL; 31 $sql = ‘execute procedure PROC_S2‘; 32 $statement = $db->prepare($sql); 33 $ret = $statement->execute(); 34 if(! $ret) 35 { 36 throw new Exception("PROC_S2"); 37 } 38 $db->commit(); 39 unset($statement); 40 unset($db); 41 $ret_value[‘CODE‘] = 0; 42 $ret_value[‘MSG‘] = ‘OK‘; 43 $ret_value[‘DATA‘] = ‘123‘; 44 return $ret_value; 45 } 46 catch (Exception $e) 47 { 48 echo ‘3‘ . PHP_EOL; 49 $db->rollBack(); 50 echo ‘4‘ . PHP_EOL; 51 $ret_value[‘CODE‘] = 1; 52 $msg = change_error_msg( $e->getMessage()); 53 $ret_value[‘MSG‘] = $msg; 54 $ret_value[‘DATA‘] = ""; 55 return $ret_value; 56 } 57 } 58 59 ?>
当存储过程PROC_S2中抛出异常时,PDO虽然执行了回滚,但PROC_S1操作的内容并没有发生回滚。数据库用的是FireBird。可能是FirdBird的PDO实现有BUG。
标签:return err proc color sage new llb cep att
原文地址:https://www.cnblogs.com/CipherLab/p/13125215.html