Re: [bdbxml] XmlModify and transactions in PHP
George Feinberg <[email protected]> Mon, 17 Apr 2006 10:13:17 -0400
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
Temo,
> I'm working on a PHP manager to handle articles on line. I have been
> using XmlModify in some scripts but when I create an environment to
> modify a document within a transaction the XmlModify doesn't apply
> the changes.
>
> My cuestion is about how to handle a XmlModify into transactions in
> PHP.
>
> I'm think that I am doing something wrong. I trying to isolate the
> transaction in a sigle scrips reading and using many of the basic
> examples.
>
> This is the php script using XmlModify into a transaction:
The problem is at least partly related to use of the transaction
to open the container. If you use the DBXML_TRANSACTIONAL
flag, you should not also pass a transaction. That, and if you
*do* pass a transaction to open or create a container, it must
be committed immediately after, and not used for anything else.
See below...
>
> <?php
> $env = new Db4Env();
> $env->open();
> $mgr = new XmlManager($env);
> $txn = $mgr->createTransaction();
Don't do above, move it down...
>
> $con = $mgr->openContainer($txn,"test.dbxml",DBXML_TRANSACTIONAL);
Change this to :
$con = $mgr->openContainer("test.dbxml",DBXML_TRANSACTIONAL);
>
> $qc = $mgr->createQueryContext();
> $uc = $mgr->createUpdateContext();
> $mod = $mgr->createModify();
Now start your transaction for the modify:
$txn = $mgr->createTransaction();
>
> $select = $mgr->prepare($txn,"/book",$qc);
> $mod->addAppendStep($select,XmlModify_Element,"section","some
> text");
> $retdoc=$mgr->query($txn,"doc('test.dbxml/book1')/book");
>
> $mod->execute($txn,$retdoc,$qc,$uc);
>
> $txn->commit();
> unset($con);
> $env->close();
> ?>
See if that helps,
Regards,
George
>
> In other side, the following script XmlModify works nicely without
> transaction:
>
> <?php
> $mgr = new XmlManager();
> $con = $mgr->openContainer("test.dbxml");
>
> $qc = $mgr->createQueryContext();
> $uc = $mgr->createUpdateContext();
> $mod = $mgr->createModify();
>
> $select = $mgr->prepare("/book",$qc);
> $mod->addAppendStep($select,XmlModify_Element,"section","some
> text");
>
> $retdoc=$mgr->query("doc('test.dbxml/book1')/book");
>
> $mod->execute($retdoc,$qc,$uc);
>
> unset($doc);
> unset($con);
> ?>
>
>
> The container and the document was created with the following
> script:
>
> <?php
> $book_name = 'book1';
> $book_content = '<book><title>This the title of the document.</
> title></book>';
> $mgr = new XmlManager();
> $con = $mgr->createContainer("test.dbxml");
> $con->putDocument($book_name, $book_content);
> $doc = $con->getDocument($book_name);
> $s = $doc->getContentAsString();
> print $doc->getName(). " = $s\n";
>
> unset($doc);
> unset($con);
> ?>
>
>
> Thanks for any help you can offer!
> Regards,
> Temo
------------------------------------------
To remove yourself from this list, send an
email to [email protected]