Execute a XQuery with PHP

前端 未结 8 846
青春惊慌失措
青春惊慌失措 2020-11-30 13:02

How to execute a XQuery in PHP? Can you give me an example?

Thank you.

8条回答
  •  旧巷少年郎
    2020-11-30 13:09

    pear package: http://www.pecl.php.net/package/Zorba (error 404 link)

    NEW (2011): http://www.zorba-xquery.com/html/entry/2011/12/27/PHP_Meets_XQuery

    zorba documentation: http://www.zorba-xquery.com/

    zorba docs provide a simple example:

    //Include for the Object-Oriented API
    require ‘zorba_api.php’;
    
    //Initialization of Zorba store
    $store = InMemoryStore::getInstance();
    //Initialization of Zorba
    $zorba = Zorba::getInstance($store);
    
    $xquery = <<< EOT
    let $message := ‘Hello World!’
    return
    
       {$message}
    
    EOT;
    
    //Compile the query
    $lQuery = $zorba->compileQuery($xquery);
    //Run the query…
    echo $lQuery->execute();
    //…and destroy it
    $lQuery->destroy();
    
    //Shutdown of Zorba
    $zorba->shutdown();
    //Shutdown of Zorba store
    InMemoryStore::shutdown($store);
    

提交回复
热议问题