PHP code example of bcdh / exist-db-rest-client

1. Go to this page and download the library: Download bcdh/exist-db-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bcdh / exist-db-rest-client example snippets


use BCDH\ExistDbRestClient\ExistDbRestClient;

$q = 'for $cd in /CD[./ARTIST=$artist] return $cd';

$connection = new ExistDbRestClient();

$query = $connection->prepareQuery();
$query->bindVariable('artist', 'Bonnie Tyler');
$query->setCollection("CDCatalog");
$query->setQuery($q);

$result = $query->get();
$document = $result->getDocument();

array(
    array(
        'name' => '{}CD',
        'value' => array(
            0 => array(
                'name' => '{}TITLE',
                'value' => 'Empire Burlesque',
                'attributes' => array(),
            ),
            1 => array(
                'name' => '{}ARTIST',
                'value' => 'Bob Dylan',
                'attributes' => array(),
            ),
            2 => array(
                'name' => '{}COUNTRY',
                'value' => 'USA',
                'attributes' => array(),
            ),
            3 => array(
                'name' => '{}COMPANY',
                'value' => 'Columbia',
                'attributes' => array(),
            )
        ),
        'attributes' =>  array (
            'favourite' => '1',
        ),
    ),
);

$result = $query->get();
$document = $result->getDocument();
$singleCd = $document[0];

$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $singleCd);

$result = $query->get();
$document = $result->getDocument();
$rootTagName = '{}catalog';

$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $document, $rootTagName);