Search code examples
phpapacheneo4jdirectorygraphaware

Fatal error: Uncaught Error: using graphaware for PHP


I am using graphaware to connect to a neo4j graph database. I keep getting an error saying Fatal error: Uncaught Error even though I'm using the library in composer.json. Here is the code for the autoload.php:

    <?php
/*
 * This file is part of the GraphAware Neo4j PHP OGM package.
 *
 * (c) GraphAware Ltd <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
error_reporting(E_ALL | E_STRICT);
$basedir = __DIR__.'/../';
//$basedir = __DIR__.'C:/xampp/htdocs/';
$proxyDir = $basedir.DIRECTORY_SEPARATOR.'_var';
putenv("basedir=$basedir");
putenv("proxydir=$proxyDir");
$loader = require_once __DIR__.'/../vendor/autoload.php';

Here us the code for the configuration php file named configNeo4j.php:

<?php
// Connection to the database

require_once __DIR__.'/vendor/autoload.php';

use GraphAware\Neo4j\Client\Client;
use GraphAware\Neo4j\Client\ClientBuilder;
$client = new Client ();

$client = ClientBuilder::create ()
->addConnection ( 'default', 'http://neo4j:[email protected]:7474' )
-> addConnection('bolt', 'bolt://neo4j:[email protected]:7687')
->build ();

$query = "MATCH (X) RETURN X";
$result = $client->run ( $query );
?>

Here is an image of the file structure:

enter image description here

Now when I run the webpage on a web browser which I am doing using xampps apache server I get this error message:

Fatal error: Uncaught Error: Class 'GraphAware\Neo4j\Client\Client' not found in C:\xampp\htdocs\configNeo4j.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\configNeo4j.php on line 11

This might also help:

enter image description here

This is strange because I am using the library in eclipse and I have also installed the composer in the php.exe file in xampp. If anyone has any solution to this problem it would be great if you could let me know how this problem can be fixed.Thanks in advance.


Solution

  • try this:

    require_once __DIR__.'/vendor/autoload.php';
    

    your code is:

    require_once __DIR__.'C:/xampp/htdocs/vendor/autoload.php';
    

    you dont need to specify the full path of the files ('c:/xampp/...')

    __DIR__ will give you the current directory of the file you wrote your codes
    

    oh and anyway, did you edit the autoload.php? if you use third party classes or plugins, you should not have to edit their core files.