我知道这个话题是重复性的,但是我做不到... ir在我的cmd中运行
C:\ Users \ Asus>作曲家需要graphaware / neo4j-php-client
我使用以下代码:
<?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'));
}
我有这个错误 注意:未定义的索引:77行上的C:\ Users \ Asus \ vendor \ graphaware \ neo4j-php-client \ src \ Connection \ Connection.php中的方案
注意:未定义的索引:第77行上的C:\ Users \ Asus \ vendor \ graphaware \ neo4j-php-client \ src \ Connection \ Connection.php中的主机
警告:stream_socket_client():无法连接到C:\ Users \ Asus \ vendor \ graphaware \ neo4j-中的tcp://://:7687:7687(所请求的地址在其上下文中无效。) 167行上的bolt \ src \ IO \ StreamSocket.php
致命错误:未捕获的异常'GraphAware \ Bolt \ Exception \ IOException'和消息'连接到服务器的错误(10049):“在C:\ Users \ Asus中请求的地址在上下文中无效。 \ vendor \ graphaware \ neo4j-bolt \ src \ IO \ StreamSocket.php:170堆栈跟踪:#0 C:\ Users \ Asus \ vendor \ graphaware \ neo4j-bolt \ src \ IO \ StreamSocket.php(189):GraphAware \ Bolt \ IO \ StreamSocket-> connect()#1 C:\ Users \ Asus \ vendor \ graphaware \ neo4j-bolt \ src \ Driver.php(114):GraphAware \ Bolt \ IO \ StreamSocket-> reconnect()# 2 C:\ Users \ Asus \ vendor \ graphaware \ neo4j-bolt \ src \ Driver.php(98):GraphAware \ Bolt \ Driver-> handshake()#3 C:\ Users \ Asus \ vendor \ graphaware \ neo4j- php-client \ src \ Connection \ Connection.php(164):GraphAware \ Bolt \ Driver-> session()#4 C:\ Users \ Asus \ vendor \ graphaware \ neo4j-php-client \ src \ Connection \ Connection。 php(115):GraphAware \ Neo4j \ Client \ Connection \ Connection-> checkSession()#5 C:\ Users \ Asus \ vendor \ graphaware \ neo4j-php-client \ src \ Client.php(45):GraphAware \ Neo4j \ Client \ Connection \ Connection-> run(' UNWIND {pairs ... ...',Array,NULL)#6 C在C:\ Users \ Asus \ vendor \ graphaware \ neo4j-bolt \ src \ IO \ StreamSocket.php在第170行
答案 0 :(得分:1)
堆栈跟踪看起来像它无法解析连接URL,因为它看起来像是没有方案和 host 。
在我看来,它可以追溯到您发布的代码中的这一行:
$client->run($insert_query, ["pairs" => $data]);
我认为最终将使用此行定义的URL:
$neo4j_url = "neo4j@bolt://localhost:11004";
但是这种格式在我看来错了;当用户名和密码作为URL的一部分提供时,格式为:
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
而authority
部分是:
authority = [ userinfo "@" ] host [ ":" port ]
所以我认为您想要的网址是:
$neo4j_url = "http://neo4j:bolt@localhost:11004/"; -or-
$neo4j_url = "bolt://neo4j:password@localhost:11004/"; <-- from doc linked in comment
其中有些是猜测,但我希望这能解决问题,或使您走上正确的道路。
有关URI格式的参考:https://tools.ietf.org/html/rfc3986