I am running neo4j 4.1.12 and can connect via bolt in my browser using my login credentials. I am also using https://github.com/neo4j-php/neo4j-php-client the PHP Client for Neo4j and have setup the following code:
public function __construct($table = null){
$config = config('Database')->neo4j;
if (!empty($config['Username'])){
$auth = Authenticate::basic($config['Username'],$config['Password']);
} else {
$auth = null;
}
$this->transact = $config['Transact']; // allows config setting of whether to use the Transaction feature
$this->client = ClientBuilder::create()->withDriver('bolt','bolt://neo4j:PW_THAT_WORKS@localhost:7687')->build();
$this->table = $table;
}
public function query($query,$params = []){
$client = $this->client;
$statement = new Statement($query,$params);
if ($this->transact){
$result = $client->writeTransaction(static function (TransactionInterface $tsx) use ($statement) {
return $tsx->runStatement($statement);
});
} else {
$result = $client->runStatement($statement);
}
return $result;
}
public function insert($data = null, bool $returnID = true){
if (empty($this->table)){
return false;
}
$result = $this->query('CREATE ('.$this->table. ')');
print'<pre>';print_r($result);print'</pre>';
}
However when I call:
$neo4j = new \App\Models\Neo4jModel('n:Test');
$neo4j->insert(array('Hello'=>'World','Foobar'=>'Baz'));
I get a connection error saying Cannot connect to any server on alias: bolt with Uris: ('bolt://neo4j:PW_THAT_WORKS@localhost:7687') and I have absolutely no idea why !? And the following Cypher query neo4j$ CREATE (n:Test) works absolutely fine: Added 1 label, created 1 node, completed after 408 ms.
Also if I try the http driver I get Http\Discovery\Exception\DiscoveryFailedException - which I know looks obvious but as I say, my browser can access localhost fine! I am accessing from subdomain.localhost but that shouldn't be an issue surely?
And running curl produces the following:
curl localhost:7474 { "bolt_routing" : "neo4j://localhost:7687", "transaction" : "http://localhost:7474/db/{databaseName}/tx", "bolt_direct" : "bolt://localhost:7687", "neo4j_version" : "4.1.12", "neo4j_edition" : "community" }
Please can someone explain why this wouldn't be connecting and what I need to do to fix it?
I've run into the same issue while working to upgrade from neo4j v3.51 to a new version (converting to the newer php client before making the n4j version switch).
It's not in the docs from what I can tell, but within the code you'll find that the neo4j-php-client only supports bolt protocol versions 4.4.* and ^5.0. Given that, and based on neo4j's bolt protocol compatibility table, this would mean that you must use a neo4j version of v4.4 or greater to make use of Bolt with this client. Note that the client's underlying Bolt driver (by stefanak-michal) does support lesser protocol versions, so if you really need Bolt and can't upgrade your DB version, using that directly might be an option.
For completeness, it's within the ProtocolFactory::createProtocol() where you'll find your Bolt connection is failing: