Example #1
0
EXPECTED RESULT:
book1 = <book><title>Knowledge Discovery in Databases.</title></book>
ACTUAL RESULT:
<?php 
#
# This is a very simple example of using try/catch and XmlException
# to get information on an exception thrown from Berkeley DB XML.
# The line that generates the exception is the query, which uses
# bad XQuery syntax.
#
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
$mgr = new XmlManager();
try {
    $con = $mgr->createContainer("test.dbxml");
    $con->putDocument($book_name, $book_content);
    $qc = $mgr->createQueryContext();
    $res = $mgr->query("collection('test.dbxml')/x[", $qc);
    $doc = $con->getDocument("foo");
    $s = $doc->getContentAsString();
    print $doc->getName() . " = {$s}\n";
    unset($doc);
    unset($con);
} catch (XmlException $xe) {
    print "XmlException message: " . $xe->what() . "\n";
    print "XmlException code: " . $xe->getExceptionCode() . "\n";
    print "XmlException dbErrno: " . $xe->getDbErrno() . "\n";
    print "Query line: " . $xe->getQueryLine() . "\n";
    print "Query column: " . $xe->getQueryColumn() . "\n";
    unset($con);
}
Example #2
0
File: 10.php Project: kanbang/Colt
Create two XML Containers within a Berkeley DB environment,
then within a Berkeley DB transaction add a document to
each container.

EXPECTED RESULT:
Success
ACTUAL RESULT:
<?php 
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
foreach (array_merge(glob("__db*"), glob("log.O"), glob("test*.dbxml")) as $file) {
    @unlink($file);
}
$env = new Db4Env();
$env->open();
$mgr = new XmlManager($env);
$config = new XmlContainerConfig();
$config->setTransactional(true);
$mgr->setDefaultContainerConfig($config);
$con1 = $mgr->createContainer("test.dbxml");
$con2 = $mgr->createContainer("test2.dbxml");
$txn = $mgr->createTransaction();
$con1->putDocument($txn, $book_name, $book_content);
$con2->putDocument($txn, $book_name, $book_content);
$txn->commit();
unset($con1);
unset($con2);
unset($mgr);
$env->close();
print "Success\n";