php mysql xa事务_XA mysql php 分布式事务
$XA=uniqid("");$db->query("XASTART'$XA'");$db1->query("XASTART'$XA'");$insert1="insertintomytablevalues(?,?,?,?,?)";$params=array(12345678,123456789,444,555,1);$db->inser...
$XA = uniqid("");
$db -> query("XA START '$XA'");
$db1 -> query("XA START '$XA'");
$insert1 = "insert into mytable values(?,?,?,?,?)";
$params = array(12345678,123456789,444,555,1);
$db -> insert($insert1,$params);
$db1 -> insert($insert2,$params);
$db -> query("XA END '$XA'");
$db -> query("XA PREPARE '$XA'");
$db1 -> query("XA END '$XA'");
$db1 -> query("XA PREPARE '$XA'");
try{
$db -> query("XA COMMIT '$XA'");
throw new Exception("exception");
$db1 -> query("XA COMMIT '$XA'");
}catch(Exception $e){
$db -> query("XA ROLLBACK '$XA'");
$db1 -> query("XA ROLLBACK '$XA'");
}
代碼如上,$db和$db1連接了兩個主機上的mysql:
服務(wù)會報錯XAER_RMFAIL: The command cannot be executed when global transaction is in the NON-EXISTING state
而且查看數(shù)據(jù)庫,$db數(shù)據(jù)插入成功了,$db沒成功。沒有起到分布式事務(wù)的作用。
如何確保分布式事務(wù)都能回滾?
展開
總結(jié)
以上是生活随笔為你收集整理的php mysql xa事务_XA mysql php 分布式事务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 仿照LFW的pair.txt生成自己数据
- 下一篇: mysql的rows大小超过8126_m