Databases Reference
In-Depth Information
In Example 3-15 on page 118, XML ContentStore $xcs has been given a name,
so $xcs only manages XML data related to specific application blogs . Other
content stores can be created to manage other types of XML data.
Zend_Db_Xml_ContentStore knows how to access the persistence layer to
perform Create, Read, Update, and Delete (CRUD) operations and abstracts
these operations by using convenience methods. For example, if the persistence
layer is a relational database, a call to the method insert() builds an appropriate
SQL insert statement based on the structure of the underlying tables used and
the content of the Zend_Db_Xml_Content object. It connects to the database
and executes the statement. Other CRUD methods work in a similar fashion and
include update(), delete(), deleteById(), and selectAll(). Example 3-16 shows
how to save XML data in the XML ContentStore.
Example 3-16 Saving XML data in the XML ContentStore
// create an Zend_Db_Xml_Content object from a file
// using a utility method
$xmldoc = Zend_Db_Xml_XmlUtil::createDocument();
$xmldoc = Zend_Db_Xml_XmlUtil::importXmlFile('data.xml');
//save the XML document to the persistence layer
$xcs → insert($xmldoc);
Similar functions exist for update and delete. In addition,
Zend_Db_Xml_ContentStore also contains a simple search facility that retrieves
Zend_Db_Xml_Content by its ID or by searching within the XML data or the
metadata in Zend_Db_Xml_Content. The search on XML data is done using
XPath expressions. Some of these methods are find() and findById().
Zend_Db_Xml_ContentStore_DB2
The class XMLContentStoreDB2 is implemented using the DB2 adapter which in
turn uses the ibm_db2 CLI driver. For example, to insert, the application gives
the XCS an XMLContent object and the XMLContentStoreDB2 takes care of the
underlying details. Because DB2 9 supports a native XML data type, one
Zend_Db_Xml_ContentStore_DB2 object maps to one table with four columns
named as ID , DATA , ABOUT , and ATTACHMENT . The table columns are defined as
follows:
ID is a unique integer and is used as the primary key of the table.
DATA is defined as an XML column.
ABOUT is defined as an XML column.
ATTACHMENT is defined as a BLOB column.
Search WWH ::




Custom Search