Question

I have a php array $id=[12344,546674,6789];

I want to set this array as the value of the property id of the relationship :knows , represented as

(:user)-[:knows{id:[]}]->(:data)

I use everyman php plugin for neo4j

I have tried the below query , but it gave an error Array cannot be converted to string

    $id=[12344,546674,6789];
    $client = new Everyman\Neo4j\Client();
    $query= "match (u:user{id:".$user_id."})-[r:knows]->(c:data)
             set r.id=".$id."";
    $result = new Everyman\Neo4j\Cypher\Query($client, $query);

Please help, Thanks in advance

Was it helpful?

Solution

Finally I found the solution,

I am posting this answer to help other people having the same doubt.

Instead of directly specifying the array in the cypher query , you could use it like this

$id=[12344,546674,6789];
$client = new Everyman\Neo4j\Client();
$query= "match (u:user{id:".$user_id."})-[r:knows]->(c:data)
         set r.id={myid}";
$result = new Everyman\Neo4j\Cypher\Query($client, $query,array('myid' => $id));

Hope this helps, Thank you

OTHER TIPS

set r.id=".$id."";

Wrong! You can't convert array to string! It is php error, not neo4j

In cypher arrays are represented as [1,2,3] Query should looks like

 $query= "match (u:user{id:".$user_id."})-[r:knows]->(c:data)
             set r.id=[" . implode(',', $id) . "]";

It is even better to use statement params, but i don't know the exact syntax. Should be something like:

$params = array( 'id' => $id');
$query= "match (u:user{id:".$user_id."})-[r:knows]->(c:data)
             set r.id= {id} ";
    $result = new Everyman\Neo4j\Cypher\Query($client, $query, $params);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top