i know this topic is Repetitious but I cant do it... ir run this in my cmd
C:\Users\Asus> composer require graphaware/neo4j-php-client
and i use this code:
<?php
/**
* To install Neo4j-PHP-Client, we use Composer
*
* $ curl -sS https://getcomposer.org/installer | php
* $ php composer.phar require graphaware/neo4j-php-client
*
*/
require 'C:\Users\Asus\vendor\autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
// change to your hostname, port, username, password
$neo4j_url = "neo4j@bolt://localhost:11004";
// setup connection
$client = ClientBuilder::create()
->addConnection('default', $neo4j_url)
->build();
// setup data
$insert_query = <<<EOQ
UNWIND {pairs} as pair
MERGE (p1:Person {name:pair[0]})
MERGE (p2:Person {name:pair[1]})
MERGE (p1)-[:KNOWS]-(p2);
EOQ;
// friend data to insert
$data = [["Jim","Mike"],["Jim","Billy"],["Anna","Jim"],
["Anna","Mike"],["Sally","Anna"],["Joe","Sally"],
["Joe","Bob"],["Bob","Sally"]];
// insert data
$client->run($insert_query, ["pairs" => $data]);
// friend of friend: query
$foaf_query = <<<EOQ
MATCH (person:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf)
WHERE person.name = {name}
AND NOT (person)-[:KNOWS]-(foaf)
RETURN foaf.name AS name
EOQ;
// friend of friend: build and execute query
$params = ['name' => 'Joe'];
$result = $client->run($foaf_query, $params);
foreach ($result->records() as $record) {
echo $record->get('name') . PHP_EOL;
}
// common friends: query
$common_friends_query = <<<EOQ
MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf:Person)
WHERE user.name = {user} AND foaf.name = {foaf}
RETURN friend.name AS friend
EOQ;
// common friends: build and execute query
$params = ['user' => 'Joe', 'foaf' => 'Sally'];
$result = $client->run($common_friends_query, $params);
foreach ($result->records() as $record) {
echo $record->get('friend') . PHP_EOL;
}
// connecting paths: query
$connecting_paths_query = <<<EOQ
MATCH path = shortestPath((p1:Person)-[:KNOWS*..6]-(p2:Person))
WHERE p1.name = {name1} AND p2.name = {name2}
RETURN [n IN nodes(path) | n.name] as names
EOQ;
// connecting paths: build and execute query
$params = ['name1' => 'Joe', 'name2' => 'Billy'];
$result = $client->run($connecting_paths_query, $params);
foreach ($result->records() as $record) {
print_r($record->get('names'));
}
and i have this error Notice: Undefined index: scheme in C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php on line 77
Notice: Undefined index: host in C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php on line 77
Warning: stream_socket_client(): unable to connect to tcp://://:7687:7687 (The requested address is not valid in its context. ) in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php on line 167
Fatal error: Uncaught exception 'GraphAware\Bolt\Exception\IOException' with message 'Error to connect to the server(10049) : "The requested address is not valid in its context. "' in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php:170 Stack trace: #0 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php(189): GraphAware\Bolt\IO\StreamSocket->connect() #1 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\Driver.php(114): GraphAware\Bolt\IO\StreamSocket->reconnect() #2 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\Driver.php(98): GraphAware\Bolt\Driver->handshake() #3 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php(164): GraphAware\Bolt\Driver->session() #4 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php(115): GraphAware\Neo4j\Client\Connection\Connection->checkSession() #5 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Client.php(45): GraphAware\Neo4j\Client\Connection\Connection->run('UNWIND {pairs} ...', Array, NULL) #6 C in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php on line 170
The stack trace looks like it cannot parse the connection URL, because it looks like it is coming up with no scheme and no host.
It looks to me like it traces back to this line in the code you posted:
$client->run($insert_query, ["pairs" => $data]);
which I think is ultimately using the URL defined on this line:
$neo4j_url = "neo4j@bolt://localhost:11004";
but that format looks wrong to me; when username and password are provided as part of a URL, the format is:
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
and the authority
portion is:
authority = [ userinfo "@" ] host [ ":" port ]
So the URL I think you want is :
$neo4j_url = "http://neo4j:bolt@localhost:11004/"; -or-
$neo4j_url = "bolt://neo4j:password@localhost:11004/"; <-- from doc linked in comment
Some of this is guesswork, but I hope this solves it, or sets you on the right path to solving it.
Reference for the format of a URI : https://tools.ietf.org/html/rfc3986