Reputation: 11
I am trying to use the Neo4j server for my database and i am trying to make a connection to it from a php code. I am running my php on WAMPSERVER 2.0 and have the apache server 2.2.11 running with it. Can anyone please tell me what exactly is to be installed now and how? Thank you
Upvotes: 0
Views: 1111
Reputation: 37
I am pretty new to the whole programming thing but what I did is follow this post here->https://github.com/graphaware/neo4j-php-client You'll need this to retrieve the necessary files required to run queries etc.
Then after you successfully installed composer and run Neo4j-PHP-client. Transfer the vendor folder to your 'htdoc' folder for XAMP or it would be the 'www' folder for those using WAMP server.
Just run the code below in your php file to connect to the Neoj4 database and have fun! :)
<?php
require_once 'vendor/autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default', 'http://neo4j:password@localhost:7474')
//Example for HTTP connection configuration (port is optional)
->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
// Example for BOLT connection configuration (port is optional)
->build();
?>
Upvotes: 1
Reputation: 11
first download Neo4j from here i.e the community version, and follow your normal windows install routine. The tricky part is accessing the server from php here's a quick example to get you started. PS// Make sure the neo4j server is running before trying this.
$data=array("query" => "Match (n) RETURN n",
"params" => array ());
$data=json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://localhost:7474/db/data/cypher/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Accept: application/json; charset=UTF-8','Content-Type: application/json','Content-Length: ' . strlen($data),'X-Stream: true'));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
$result1 = curl_exec($curl);
//echo $result1;
curl_close($curl);
$result=json_decode($result1,TRUE);
var_dump ($result);
Upvotes: 1