Generating an XML from a database result

Generating an XML from a database may be useful in several ways, perhaps you wish to send data from a query across a network using a SOAP request, or perhaps you're using it to build some data for a web service. Whatever your purpose, this is how to do it—also we'll look at some real-world uses—for example, we'll generate the XML output from a database query.

Getting ready

Firstly, we need to create a table and enter some example data so that you'll see some data in the CSV format, so with that in mind, copy the following code into SQL:

CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_first_name` varchar(125) NOT NULL, `user_last_name` varchar(125) NOT NULL, `user_email` ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.