Skip to content

Commit b965f77

Browse files
committed
winp
1 parent 95f7d33 commit b965f77

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/Neo4jQueryAPI_script.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php'; // Ensure you include the autoloader for your dependencies
4+
5+
use Neo4j\QueryAPI\Neo4jQueryAPI;
6+
use Neo4j\QueryAPI\Objects\Authentication;
7+
8+
try {
9+
// Configuration
10+
$neo4jHost = 'https://6f72daa1.databases.neo4j.io/'; // Replace with your Neo4j host
11+
$username = 'neo4j'; // Replace with your Neo4j username
12+
$password = '9lWmptqBgxBOz8NVcTJjgs3cHPyYmsy63ui6Spmw1d0'; // Replace with your Neo4j password
13+
$database = 'neo4j'; // Default database (replace if needed)
14+
15+
// Authentication setup
16+
$auth = Authentication::basic($username, $password);
17+
18+
// Initialize the Neo4jQueryAPI instance
19+
$neo4j = Neo4jQueryAPI::login($neo4jHost, $auth);
20+
21+
// Run a sample Cypher query
22+
$cypherQuery = 'MATCH (n) RETURN n LIMIT 10'; // Replace with your desired query
23+
$parameters = []; // Optional query parameters
24+
25+
$resultSet = $neo4j->run($cypherQuery, $parameters, $database);
26+
27+
// Output the results
28+
echo "Query executed successfully!\n";
29+
foreach ($resultSet->getRows() as $row) {
30+
echo json_encode($row->toArray(), JSON_PRETTY_PRINT) . "\n";
31+
}
32+
33+
// Output result counters
34+
$counters = $resultSet->getCounters();
35+
echo "Nodes created: " . $counters->getNodesCreated() . "\n";
36+
echo "Nodes deleted: " . $counters->getNodesDeleted() . "\n";
37+
} catch (Exception $e) {
38+
// Handle errors
39+
echo 'Error: ' . $e->getMessage() . "\n";
40+
if ($e instanceof \Neo4j\QueryAPI\Exception\Neo4jException) {
41+
echo 'Neo4j Error Details: ' . json_encode($e->getErrorDetails(), JSON_PRETTY_PRINT) . "\n";
42+
}
43+
}

src/Neo4jRequestFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Neo4j\QueryAPI;
44

5-
use InvalidArgumentException;
65

76
class Neo4jRequestFactory
87
{

src/requestFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
echo "Transaction ID: {$transactionId}" . PHP_EOL;
4646

47-
// Step 2: Run the Cypher query within the transaction
4847
$runQueryRequest = $requestFactory->buildRunQueryRequest($database, $cypher, $parameters);
4948
$runQueryResponse = $client->request(
5049
$runQueryRequest['method'],

0 commit comments

Comments
 (0)