neoxygen / neo4j-neoclient

Simple PHP HttpClient for the Neo4j ReST API with Multi DB Support
MIT License
121 stars 138 forks source link

how to send params with query while sending query to the database #39

Closed itsneel closed 9 years ago

itsneel commented 9 years ago

How to send params with query while sending query to the database. as in all the examples, i have seen that are fetching some thing and not sending any params with it. Could you guys please post and example explaining how i can do that?

ikwattro commented 9 years ago

Hi @neelanshugoyal ,

As mentioned in the documentation (true there is no example) you need to pass an array of parameters.

So for example, retrieving a user by id :

$query = 'MATCH (user:User) WHERE id(user) = {user_id} RETURN user';
$parameters = array('user_id' => 123);
$result = $client->sendCypherQuery($query, $parameters)->getResult();

You can also use arrays as parameters values, for e.g. retrieving a user who's id is in a collection of ids :

$query = 'MATCH (user:User) WHERE id(user) IN {ids} RETURN user';
$parameters = array('user_id' => array(123, 234, 456));
$result = $client->sendCypherQuery($query, $parameters)->getResult();

In the meantime, I wrote two blog posts on Sitepoint which have more examples in a real use case :

http://www.sitepoint.com/discover-graph-databases-neo4j-php/

http://www.sitepoint.com/adding-social-network-features-php-app-neo4j/

Hope it helps

itsneel commented 9 years ago

@ikwattro thanks, for the examples, i ll implement them. And i am closing this issue as well.

itsneel commented 9 years ago

also could you please update the documentation so that other can benefit from it. Thanks