Get error when run cypher query multi line in php

I get this error while that run this query cypher from luadis php driver Single line query runed but multi line query cypher doesn't run

$hosturl =  self::$config['hosturl'];
$result = $client->run("
            UNWIND range(0,4) as level
            CALL apoc.cypher.doIt('
            MATCH (c:Category { pagesFetched: false, level: $level })
            CALL apoc.load.json('$hosturl/w/api.php?format=json&action=query&list=categorymembers&cmtype=page&cmtitle=Category:' + apoc.text.urlencode(c.catName) + '&cmprop=ids|title&cmlimit=500')
            YIELD value as results
            UNWIND results.query.categorymembers AS page
            MERGE (p:Page {pageId: page.pageid})
            ON CREATE SET p.pageTitle = page.title, p.pageUrl = '$hosturl/wiki/' + apoc.text.urlencode(replace(page.title, ' ', '_'))
            WITH p,c
            MERGE (p)-[:IN_CATEGORY]->(c)
            WITH DISTINCT c
            SET c.pagesFetched = true', { level: level }) yield value
            return value");
        

And i get this error :

[Sat Feb 19 00:27:39 2022] PHP Fatal error:  Uncaught Bolt\error\MessageException: Invalid input 'h': expected whitespace, '.', node labels or rel types, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 5,
column 25 (offset: 141))
"                       CALL apoc.load.json('https://en.wikipedia.org/w/api.php?format=json&action=query&list=categorymembers&cmtype=page&cmtitle=Category:' + apoc.text.urlencode(c.catName) + '&cmprop=ids|title&cmlimit=500')"
                         ^ (Neo.ClientError.Statement.SyntaxError) in C:\xampp\htdocs\Graph\vendor\stefanak-michal\bolt\src\protocol\V3.php:82
Stack trace:
#0 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Bolt\BoltUnmanagedTransaction.php(131): Bolt\protocol\V3->run()
#1 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Bolt\Session.php(87): Laudis\Neo4j\Bolt\BoltUnmanagedTransaction->runStatements()
#2 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Client.php(77): Laudis\Neo4j\Bolt\Session->runStatements in C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Exception\Neo4jException.php on line 50
[Sat Feb 19 00:27:39 2022] [::1]:1194 [500]: GET /querycypher.php - Uncaught Bolt\error\MessageException: Invalid input 'h': expected whitespace, '.', node labels or rel types, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, O
R, ',' or ')' (line 5, column 25 (offset: 141))
"                       CALL apoc.load.json('https://en.wikipedia.org/w/api.php?format=json&action=query&list=categorymembers&cmtype=page&cmtitle=Category:' + apoc.text.urlencode(c.catName) + '&cmprop=ids|title&cmlimit=500')"
                         ^ (Neo.ClientError.Statement.SyntaxError) in C:\xampp\htdocs\Graph\vendor\stefanak-michal\bolt\src\protocol\V3.php:82
Stack trace:
#0 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Bolt\BoltUnmanagedTransaction.php(131): Bolt\protocol\V3->run()
#1 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Bolt\Session.php(87): Laudis\Neo4j\Bolt\BoltUnmanagedTransaction->runStatements()
#2 C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Client.php(77): Laudis\Neo4j\Bolt\Session->runStatements in C:\xampp\htdocs\Graph\vendor\laudis\neo4j-php-client\src\Exception\Neo4jException.php on line 50
[Sat Feb 19 00:27:39 2022] [::1]:1194 Closing

Please say to me how to solve this Please help me

1 answer

  • answered 2022-02-21 14:07 Ghlen

    I don't really understand the usage of the apoc call. You can just inline the query like this:

    $result = $client->run(<<<'CYPHER'
                UNWIND range(0,4) as level
                MATCH (c:Category { pagesFetched: false, level: level })
                CALL apoc.load.json($hostUrl + '/w/api.php?format=json&action=query&list=categorymembers&cmtype=page&cmtitle=Category:' + apoc.text.urlencode(c.catName) + '&cmprop=ids|title&cmlimit=500')
                YIELD value as results
                UNWIND results.query.categorymembers AS page
                MERGE (p:Page {pageId: page.pageid})
                ON CREATE SET p.pageTitle = page.title, p.pageUrl = '$hosturl/wiki/' + apoc.text.urlencode(replace(page.title, ' ', '_'))
                WITH p,c
                MERGE (p)-[:IN_CATEGORY]->(c)
                WITH DISTINCT c
                SET c.pagesFetched = true
                CYPHER, ['hostUrl' => $hostUrl]);
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum