Exforsys

Home arrow Reviews arrow PHP Oracle Training Tutorials

Handling Transactions

Page 2 of 2
Author : Exforsys Inc.     Published on: 4th May 2008

Taking Advantage of Standard Internet Protocols

Handling Transactions

As you can see from the preceding example, changes made through internet protocols to repository resources become permanent once a single operation on a resource has been completed.

Ads

In contrast, all SQL and PL/SQL operations that you perform on the XML data stored in Oracle XML DB are transactional, irrespective of whether you're using XMLType storage or the XML repository. This allows you to combine SQL and PL/SQL statements operating on XML data within a logical unit of work and explicitly commit the transaction or roll it back if necessary.

Suppose you want to create a folder in the XML repository and then upload an XML document in it. The following code fragment shows how this can be done in PL/SQL:

Sample Code
  1. rslt:=DBMS_XDB.createFolder('/public/xmlusr/emps/303')
  2. rslt:=DBMS_XDB.createResource('/public/xmlusr/emps/303/emp303.xml',
  3. xmldoc)
  4. COMMIT
  5.  
Copyright exforsys.com


The above PL/SQL code is transactional. If an error occurs during the execution of the createFolder function, then the results of execution of createFolder are discarded automatically.

On the other hand, when performing the same operations through FTP protocol, failure to create the resource doesn't affect the results of preceding operation. So, the following fragment of PHP code is not transactional:

Sample Code
  1. $login = ftp_login($ftpcon, $db_user, $db_pswd)
  2. ftp_chdir($ftpcon, '/public/xmlusr/emps')
  3. ftp_mkdir($ftpcon, '303')
  4. ftp_chdir($ftpcon, '/public/xmlusr/emps/303')
  5. ftp_fput($ftpcon, 'emp303.xml', $xmldoc, FTP_ASCII)
  6. ftp_close($ftpcon)
Copyright exforsys.com


Ads

NOTE: Chapter 4 Transactions, presented earlier in this book, explains in detail how to use transactions in PHP/Oracle applications.



 
This tutorial is part of a PHP Oracle Training Tutorials tutorial series. Read it from the beginning and learn yourself.

PHP Oracle Training Tutorials

 

Comments