graphaware get a returned count() value

85 views Asked by At

So I have been working around with neo4j and php-client graph aware, until now i have make it work kind of ok. Until now that i try to run a query returning a count() and can't find how to catch the information, the query that i run is the next function:

function net_in_common($user, $other){
    global $client;

    $searchquery = "MATCH (a:user)-[r:IN_NET]->(b:user)<-[s:IN_NET]-(c:user) WHERE a.username = '" . $user . "' AND c.username = '" . $other . "' return count(DISTINCT b) as incommon";

    $result = $client->run($searchquery);

    return $result;
}

but when i try to echo it by

$common = net_in_common($user1, $user2);
echo $common->value('incommon');

i get absolute and completely nothing, it even dispatch an error that break the php code but i can't find the mistake itself.

it's a different way of fetching the value of a count() or something that i should do different??

1

There are 1 answers

0
Christophe Willemsen On

The $result variable in your function returns you a Result object which itself contains a collection of ResultRecord objects (all is explained in the README of the client https://github.com/graphaware/neo4j-php-client#working-with-result-sets).

So, for reading the incommon value you would have to do :

$common = net_in_common($user1, $user2);

echo $common->firstRecord()->get('incommon');

Also, using php functions like this doesn't really reflect how we use php in (almost) 2017, maybe you can share a complete example of your project so we can investigate what's wrong, normally calling the value on a Result object should trigger an exception.