duanjitong7226 2018-11-09 04:31
浏览 158

我如何在Windows上使用neo4j与php?

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

  • 写回答

1条回答 默认 最新

  • dongyi8416 2018-11-09 05:20
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站