简体   繁体   English

如何使用 graphaware/neo4j-php-client 连接到 GrapheneDb?

[英]How do you connect to GrapheneDb using graphaware/neo4j-php-client?

I have read the instructions at both https://github.com/graphaware/neo4j-php-client#installation-and-basic-usage and https://docs.graphenedb.com/docs/php我已经阅读了https://github.com/graphaware/neo4j-php-client#installation-and-basic-usagehttps://docs.graphenedb.com/docs/php的说明

While this example from the GrapheneDb docs does work, it does not use GraphAware Neo4j PHP Client, it uses Neo4j Bolt PHP: While this example from the GrapheneDb docs does work, it does not use GraphAware Neo4j PHP Client, it uses Neo4j Bolt PHP:

// Example for Bolt
$config = \GraphAware\Bolt\Configuration::newInstance()
->withCredentials('user', 'pass')
->withTimeout(10)
->withTLSMode(\GraphAware\Bolt\Configuration::TLSMODE_REQUIRED);

$driver = \GraphAware\Bolt\GraphDatabase::driver('bolt://hobby-my-graph-db.dbs.graphenedb.com:24786', $config);
$client = $driver->session();

I can't find a working example anywhere, I have tried all kinds of things;我在任何地方都找不到一个可行的例子,我尝试了各种各样的东西; I have double and triple checked the connection strings, I have tried http as well as bolt, I have logged into the database from neo4j browser so I know the credentials must be ok.我对连接字符串进行了两次和三次检查,我已经尝试过 http 和螺栓,我已经从 neo4j 浏览器登录到数据库,所以我知道凭据必须没问题。

This is what my code looks like:这就是我的代码的样子:

/* GraphAware\Bolt\Configuration */
$config = Configuration::create()
->withCredentials('user', 'pass')
->withTimeout(10)
->withTLSMode(Configuration::TLSMODE_REQUIRED);    
        
/* GraphAware\Neo4j\Client\ClientBuilder */
$client = ClientBuilder::create()
->addConnection('bolt', 'bolt://hobby-my-graph-db.dbs.graphenedb.com:24787', $config)
->build();
    
$result = $client->run("CREATE (n:Person {name: 'Bob'}) RETURN id(n)");

When I try to run the query I get:当我尝试运行查询时,我得到:

Exception 'GraphAware\Bolt\Exception\HandshakeException' with message 'Error receiving data'
in /path-to-project/vendor/graphaware/neo4j-bolt/src/Driver.php:165

Does anyone have a complete working connection example to GrapheneDb using graphaware/neo4j-php-client?有没有人使用 graphaware/neo4j-php-client 提供到 GrapheneDb 的完整工作连接示例?

The bolt driver: For some reason GraphAware\Neo4j\Client\Connection\Connection.php does not use the configuration you pass in to the GraphAware\Neo4j\Client\ClientBuilder->addConnection() method (???).螺栓驱动程序:出于某种原因GraphAware\Neo4j\Client\Connection\Connection.php不使用您传递给GraphAware\Neo4j\Client\ClientBuilder->addConnection()方法的配置 (???)。 It rebuilds the configuration, leaving out everything except for the username and password.它重建配置,除了用户名和密码之外的所有内容都被忽略。 So, if your connection requires TLS mode like mine, it will never work without altering the source.因此,如果您的连接需要像我这样的 TLS 模式,那么如果不更改源,它将永远无法工作。

At GraphAware\Neo4j\Client\Connection\Connection.php:180 inside the buildDriver() method I simply use the configuration I passed in which is $this->config instead of the one they rebuild for you.GraphAware\Neo4j\Client\Connection\Connection.php:180buildDriver()方法中,我只是使用我传入的配置$this->config而不是他们为您重建的配置。 Works as it should.正常工作。

After alteration it looks like: $this->driver = BoltGraphDB::driver($uri, $this->config);修改后看起来像: $this->driver = BoltGraphDB::driver($uri, $this->config);

(graphaware/neo4j-php-client 4.8.5) (graphaware/neo4j-php-client 4.8.5)

Actually, just don't use graphenedb, it sucks.实际上,只是不要使用graphenedb,它很烂。 Just use https://neo4j.com/cloud/aura .只需使用https://neo4j.com/cloud/aura Works without any screwing around.无需任何操作即可工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM