neo4j- connection

0

Hello community, I'm new with Neo4j, I'm connecting from php, I just installed the neo4j server with the basic configuration, I try to make a request to the server with this code:

    require_once 'vendor/autoload.php';

use GraphAware\Neo4j\Client\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
    ->build();
$query = "MATCH (n:Person)-[:FOLLOWS]->(friend) RETURN n.name, collect(friend) as friends";
$result = $client->run($query);

foreach ($result->getRecords() as $record) {
    echo sprintf('Person name is : %s and has %d number of friends', $record->value('name'), count($record->value('friends'));
}

and I get the following error: cURL error 7: Failed to connect to localhost port 7474: Connection refused (see link )

    
asked by Jaime Roman 09.04.2018 в 22:27
source

1 answer

1

I forgot a detail that is crucial, my php code was running from a Docker container, therefore, the address to consume the Neo4j server could not be localhost , it had to be, < strong> 172.17.0.1 , now it works fine, I leave this here for someone else to use it.

Finally I created a docker file to put the PHP container and container Neo4j, here are the docker file

version: "3.2"
services:
  neo4j:
      image: neo4j:3.3.4
      ports:
        - "7474:7474"
        - "7687:7687"
  app:
    image: silex:dev
    volumes:
      - .:/var/www
    links:
      - neo4j
    ports:
      - "7018:80"

This way in the controller I can call the Neo4j in the following way (the user I use is: neo4j and the password: 1234567 ):

$client = ClientBuilder::create()
                ->addConnection('bolt', 'bolt://neo4j:1234567@neo4j:7687')
                ->build();
$query = "MATCH (n:Movie) RETURN n LIMIT 25";
$result = $client->run($query);
    
answered by 12.04.2018 / 18:02
source