【问题标题】:How to return value from an arangodb transaction in php?如何从 php 中的 arangodb 事务返回值?
【发布时间】:2018-07-14 17:15:36
【问题描述】:

我正在尝试通过以下事务返回创建的密钥:

$trans=new Transaction($connection,array( 'collections' => array( 'write' => array( 'users','group_relations','groups' ),'read'=> array( 'users','group_relations','groups' ) ), 'waitForSync' => true ));
        $trans->setAction('function(){
            var db= require("@arangodb").db;
            var ids = []; 
            db.groups.insert([{"name":"'.$name.'","type":"'.$type.'","restriction":"'.$restriction.'","picture":"'.$picture.'"}]).forEach(
              function(obj) {ids.push(obj._key);});
            db.group_relations.insert({"_from":"users/'.$_SESSION['uid'].'","_to":"groups/"+ids["0"],"status":"admin"});
            return ids["0"];
        }');
       echo $trans->execute();

有人可以帮忙解决这个问题吗?

【问题讨论】:

    标签: php transactions arangodb


    【解决方案1】:

    来自文档:

    /**
    147      * Execute the transaction
    148      *
    149      * This will post the query to the server and return the results as
    150      * a Cursor. The cursor can then be used to iterate the results.
    151      *
    152      * @throws Exception throw exception if transaction failed
    153      * @return mixed true if successful without a return value or the return value if one was set in the action
    154      */
    

    只需赋值即可。

    【讨论】:

    • 再次感谢您帮助我。如何在我的示例中打印“hello world”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2015-03-22
    • 2015-05-01
    • 2012-09-12
    相关资源
    最近更新 更多