事务错误处理不起作用Neo4jphp

时间:2014-03-01 19:04:04

标签: transactions cypher neo4jphp neo4j

我尝试在neo4j事务中使用$transaction->isError()$transaction->isClosed,但这些函数无法捕获错误。

下面是我的代码,我在提交后执行事务回滚,根据文档应该产生错误,它应该由isClosed()处理,但它从未处理错误而是产生了错误

require("vendor/autoload.php");
        use Everyman\Neo4j\Cypher\Query;
        $client = new Everyman\Neo4j\Client();

        $transaction = $client->beginTransaction();

        $queryA = new Query($client, 'CREATE (n:testing{id:189})');
        $result = $transaction->addStatements($queryA);
        $transaction->commit();
        $transaction->rollback(); // performing rollback after commit
if ($transaction->isClosed()) {
    echo "No more statements can be added!";
}

错误

Fatal error: Uncaught exception 'Everyman\Neo4j\Exception' with message 'Transaction is already closed' in C:\xampp\htdocs\feed\vendor\everyman\neo4jphp\lib\Everyman\Neo4j\Transaction.php on line 149

但实际上这个错误应由$transaction->isClosed()处理,但它没有

请提前帮助,请提供帮助

1 个答案:

答案 0 :(得分:1)

提交后无法回滚。提交会关闭事务,因此尝试回滚会引发错误。

rollback之后您不需要commit。如果任何添加的语句失败,则会自动在服务器上进行回滚。如果您的应用程序手动需要回滚事务,您只需要调用rollback,这在提交之前应该执行。