simple.php
<?php
require 'zorba_api_wrapper.php';
function example_1(Zorba $aZorba)
{
$lQuery = $aZorba->compileQuery('1+1');
echo $lQuery->execute();
$lQuery->destroy();
return true;
}
function example_2(Zorba $aZorba)
{
$lQuery = $aZorba->compileQuery('1+1');
$lIterator = $lQuery->iterator();
$lIterator->open();
$lItem = Item::createEmptyItem();
while($lIterator->next($lItem))
{
echo $lItem->getStringValue() . "\n";
}
$lIterator->close();
$lIterator->destroy();
$lQuery->destroy();
return true;
}
function example_3(Zorba $aZorba)
{
$lQuery = $aZorba->compileQuery('1 div 0');
try {
echo $lQuery->execute();
} catch ( Exception $e ) {
echo $e->getMessage() . "\n";
$lQuery->destroy();
return true;
}
$lQuery->destroy();
return false;
}
function example_4(Zorba $aZorba)
{
try {
$lQuery = $aZorba->compileQuery('for $i in (1,2,3)');
} catch ( Exception $e ) {
echo $e->getMessage() . "\n";
return true;
}
return false;
}
function example_5(Zorba $aZorba)
{
$lDataManager = $aZorba->getXmlDataManager();
$lDocMgr = $lDataManager->getDocumentManager();
$iter = $lDataManager->parseXML("<books><book>Book 1</book><book>Book 2</book></books>");
$iter->open();
$doc = Item::createEmptyItem();
$iter->next($doc);
$iter->close();
$iter->destroy();
$lDocMgr->put("books.xml", $doc);
$lQuery = $aZorba->compileQuery("doc('books.xml')//book");
echo $lQuery->execute();
$lQuery->destroy();
return true;
}
$store = InMemoryStore::getInstance();
$zorba = Zorba::getInstance($store);
print "Example1:\n";
$res = example_1($zorba);
assert($res);
print "\n\n";
print "Example2:\n";
$res = example_2($zorba);
assert($res);
print "\n\n";
print "Example3:\n";
$res = example_3($zorba);
assert($res);
print "\n\n";
print "Example4:\n";
$res = example_4($zorba);
assert($res);
print "\n\n";
print "Example5:\n";
$res = example_5($zorba);
assert($res);
print "\n\n";
$zorba->shutdown();
InMemoryStore::shutdown($store);
?>