arangodb / arangodb-php

PHP ODM for ArangoDB
https://www.arangodb.com
Apache License 2.0
183 stars 46 forks source link

Transaction query #252

Closed anonymus58 closed 6 years ago

anonymus58 commented 6 years ago

Unclear how can I run a simple query with transaction in PHP ?

I have tried this way :

$connection = new Connection($connectionOptions);

$query = 'FOR u IN Courses FILTER u.Available positions > 0 FILTER u._key == "1672779" UPDATE u WITH { Available positions: u.Available positions-1 } IN Courses RETURN NEW';

$statement = new Statement( $connection, array( "query" => $query, "count" => true, "batchSize" => 1000, "sanitize" => true ) );

    $writeCollections = ["Courses"];
    $action = "function () {
            $cursor = $statement->execute()
     }";

    $waitForSync      = true;
    $lockTimeout      = 10;

    // check if setters work fine
    $transaction                   = new Transaction($connection);
    $transaction->writeCollections = "Courses";
    $transaction->action           = $action;
    $transaction->waitForSync      = true;
    $transaction->lockTimeout      = 10;

$transaction->execute();

but i got this notice, and don`t works : Notice: Undefined variable: cursor on line 28 Notice: Undefined property: ArangoDBClient\Statement::$execute on line 28 ArangoDBClient\ServerException: 10 missing/invalid action definition for transaction - Uncaught SyntaxError: Unexpected token = - SyntaxError: Unexpected token = at new Function ()

What is the solution to run this query with transaction?

jsteemann commented 6 years ago

Does the answer provided by @Simran-B in https://github.com/arangodb/arangodb/issues/6170#issuecomment-413487455 help?

anonymus58 commented 6 years ago

Yes, thank you.