GraphAware\Neo4j\Client\Client::run PHP Method

run() public method

Run a Cypher statement against the default database or the database specified.
public run ( $query, null | array $parameters = null, null | string $tag = null, null | string $connectionAlias = null ) : GraphAware\Common\Result\Result | null
$query
$parameters null | array
$tag null | string
$connectionAlias null | string
return GraphAware\Common\Result\Result | null
    public function run($query, $parameters = null, $tag = null, $connectionAlias = null)
    {
        $connection = $this->connectionManager->getConnection($connectionAlias);
        $params = null !== $parameters ? $parameters : array();
        $statement = Statement::create($query, $params, $tag);
        $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_PRE_RUN, new PreRunEvent(array($statement)));
        try {
            $result = $connection->run($query, $parameters, $tag);
            $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_POST_RUN, new PostRunEvent(ResultCollection::withResult($result)));
        } catch (Neo4jException $e) {
            $event = new FailureEvent($e);
            $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_ON_FAILURE, $event);
            if ($event->shouldThrowException()) {
                throw $e;
            }
            return;
        }
        return $result;
    }

Usage Example

 private function createGraph()
 {
     $this->client->run('MATCH (n) DETACH DELETE n');
     $query = 'CREATE (john:User {name:"John"})-[:FRIEND]->(judith:User {name:"Judith"}),
     (john)-[:FRIEND]->(paul:User {name:"paul"}),
     (paul)-[:FRIEND]->(marc:User {name:"marc"}),
     (paul)-[:FRIEND]->(bill:User {name:"Bill"}),
     (judith)-[:FRIEND]->(bill),
     (judith)-[:FRIEND]->(sofia),
     (john)-[:FRIEND]->(sofia),
     (sofia)-[:FRIEND]->(:User {name:"Zoe"})';
     $this->client->run($query);
 }
All Usage Examples Of GraphAware\Neo4j\Client\Client::run