I tried to connect to the neo4j database using PHP and I could not do it. what am I doing wrong? Here the error:
Fatal error : Uncaught GraphAware\Bolt\Exception\MessageFailureException: Neo4j Exception "The client is unauthorized due to authentication failure." with code "Neo.ClientError.Security.Unauthorized" in C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Protocol\V1\Session.php:263 Stack trace: #0 C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Protocol\V1\Session.php(229): GraphAware\Bolt\Protocol\V1\Session->receiveMessageInit() #1 C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Protocol\V1\Session.php(59): GraphAware\Bolt\Protocol\V1\Session->init() #2 C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Protocol\SessionRegistry.php(92): GraphAware\Bolt\Protocol\V1\Session->__construct(Object(GraphAware\Bolt\IO\StreamSocket), Object(Symfony\Component\EventDispatcher\EventDispatcher), Array) #3 C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Driver.php(118): GraphAware\Bolt\Protocol\SessionRegistry->getSession(1, Array) #4 C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-php-client\src\Connection\Connection.ph in C:\xampp\htdocs\bd2\vendor\graphaware\neo4j-bolt\src\Protocol\V1\Session.php on line 263
and here the php connection code:
<?php
//require_once 'vendor/autoload.php';
require_once __DIR__ .'/vendor/autoload.php';
$client = \GraphAware\Neo4j\Client\ClientBuilder::create()
->addConnection('default', 'bolt://neo4j:pass@localhost:7687')
->build();
$query = 'MATCH (user:User {name:"john"})
CREATE (friend:User {name:"Judith"})
MERGE (user)-[r:FRIEND]->(friend)
RETURN user, friend, r';
$result = $client->sendCypherQuery($query)->getResult();
$john = $result->get('user');
$judith = $result->get('judith');
// What john has for relationships
print_r($john->getRelationships()); // returns relationships objects
// Get a node connected to john
print_r($john->getConnectedNode());
You're right, 'pass' is not my password. set the correct values and connect with neo4j perfectly well. Thank you for your help and sorry for the delay in my response.
But I get a Http\Discovery\Exception\DiscoveryFailedException because of line 2 but this goes away when removing ->addHttpConnection('backup', 'http://neo4j:password@localhost'). Full traceback is below. Any idea what might cause this error from php-http package?
**Fatal error** : Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors - Puli Factory is not available - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: . - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: Phalcon\Http\Message\RequestFactory, Nyholm\Psr7\Factory\Psr17Factory, Zend\Diactoros\RequestFactory, GuzzleHttp\Psr7\HttpFactory, Http\Factory\Diactoros\RequestFactory, Http\Factory\Guzzle\RequestFactory, Http\Factory\Slim\RequestFactory, Laminas\Diactoros\RequestFactory, Slim\Psr7\Factory\RequestFactory. in /home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php:41 Stack trace: #0 /home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/ClassDiscovery.php(79): Http\Discovery\Exception\DiscoveryFailedException::create(Array) #1 /home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php(37): Http\Discovery\ClassDiscovery::findOneByType('Psr\\Http\\Messag...') #2 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/Network/Http/HttpInjections.php(53): Http\Discovery\Psr17FactoryDiscovery::findRequestFactory() #3 [internal function]: Laudis\Neo4j\Network\Http\HttpInjections::Laudis\Neo4j\Network\Http\{closure}() #4 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/Network/Http/HttpInjections.php(115): call_user_func(Object(Closure)) #5 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/ClientBuilder.php(64): Laudis\Neo4j\Network\Http\HttpInjections->requestFactory() #6 /home/coyote/vue_test/myapp/test/neo4j.php(12): Laudis\Neo4j\ClientBuilder->addHttpConnection('backup', 'http://neo4j:Sw...') #7 {main} Next Http\Discovery\Exception\NotFoundException: No PSR-17 request factory found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation in /home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php:22 Stack trace: #0 /home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php(39): Http\Discovery\Psr17FactoryDiscovery::createException('request factory', Object(Http\Discovery\Exception\DiscoveryFailedException)) #1 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/Network/Http/HttpInjections.php(53): Http\Discovery\Psr17FactoryDiscovery::findRequestFactory() #2 [internal function]: Laudis\Neo4j\Network\Http\HttpInjections::Laudis\Neo4j\Network\Http\{closure}() #3 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/Network/Http/HttpInjections.php(115): call_user_func(Object(Closure)) #4 /home/coyote/vue_test/myapp/test/vendor/laudis/neo4j-php-client/src/ClientBuilder.php(64): Laudis\Neo4j\Network\Http\HttpInjections->requestFactory() #5 /home/coyote/vue_test/myapp/test/neo4j.php(12): Laudis\Neo4j\ClientBuilder->addHttpConnection('backup', 'http://neo4j:Sw...') #6 {main} thrown in **/home/coyote/vue_test/myapp/test/vendor/php-http/discovery/src/Psr17FactoryDiscovery.php** on line **22**
Fatal error : Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at Discovery — PHP-HTTP 1.0.0 documentation - Puli Factory is not available - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: . - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: Phalcon\Http\Message\RequestFactory, Nyholm\Psr7\Factory\Psr17Factory, Zend\Diactoros\RequestFactory, GuzzleHttp\Psr7\HttpFactory, Http\Factory\Diactoros\RequestFactory, Http\Factory\Guzzle\RequestFactory, Http\Factory\Slim\RequestFactory, Laminas\Diactoros\RequestFactory, Slim\Psr7\Factory\RequestFactory. in C:\xampp\htdocs\neo\clases\vendor\php-http\discovery\src\Exception\DiscoveryFailedException.php:41 Stack trace: #0 C:\xampp\htdocs\neo\clases\vendor\php-http\discovery\src\ClassDiscovery.php(79): Http\Discovery\E in C:\xampp\htdocs\neo\clases\vendor\php-http\discovery\src\Psr17FactoryDiscovery.php on line 22
Hello, the same thing happened to me " Fatal error : Uncaught Http\Discovery\Exception\DiscoveryFailedException....".
The solution is to install the missing libraries. The HTTP protocol requires psr-7, psr-17 and psr-18 implementations. If there are not any available, composer can install them.