Chapter 7. PHP, XML, and Databases
"If we spoke a different language, we would perceive a somewhat different world."Ludwig Wittgenstein
XML works by marking up data with descriptive tags. Databases work by tabulating information into rows and columns. Though the two approaches are fundamentally different, they share a common goal: to impose order on unstructured data in order to make it more useful.Now, contrary to what you might have heard, XML is not the panacea for all the world's ills. The language does have limitations, which may render it unsuitable for use in particular situationsa fact amply attested to by the numerous web sites that continue to prefer databases for information storage and retrieval, even in this age of XML. Consequently, web application developers need a thorough understanding of the advantages and disadvantages of these two technologies, and must factor them into their calculations when making project-wide implementation decisions.Often, however, merely understanding the issues involved is insufficient. When it comes to redeploying database-powered web applications to use XML, or exchanging information between sites or applications built on different back ends (some using XML, some using a database), a developer also needs a practical understanding of how to reconcile the two technologies in order to offer customers the most bang for their buck.This chapter examines the relationship between XML and databases, demonstrating how technologies discussed previously in this book (SAX, DOM, and XSLT) can be mobilized to translate database records into well-formed XML documents, and vice-versa. It also includes a brief discussion of the pros and cons of these two technologies, with a view to helping you choose the right one for your particular requirements.