Create XML file from mysql table

Hello Experts today i will discus about a XML write function and this XML value come from mysql table. Its very simple for use. Here is a sample mysql table and steps are described. I think it will be helpful for Experts…

* writeXML : Converting mysql table into XML
* @author : S.M. Saidur Rahman ,
* Moderator, joomla_experts (
Moderator, cakephpexperts (
* URL:
* @version : 1.0
* @date 2008-07-09
* Purpose : Write XML file and collect data from mysql table

#Create a table name “sampletable”
#Create a XML file name “sample.xml”
#Correct root path as define value
#Call this function and Enjoy!

//Here is an example of mysql table
CREATE TABLE `sampletable` (
`id` int(11) NOT NULL auto_increment,
`image` varchar(255) collate latin1_general_ci NOT NULL,
`thumbnail` varchar(255) collate latin1_general_ci NOT NULL,
`caption` varchar(150) collate latin1_general_ci NOT NULL,
`ordering` int(11) NOT NULL default ‘0’,

//Define XML file root path

//XML write function
function writeXML($xmlfile, $tablename)
$xmlfile_path= ROOT_PATH.”/”.$xmlfile;
$query_xmlw = “SELECT * FROM $tablename ORDER BY ordering DESC”;
$result_xmlw = mysql_query($query_xmlw);

$xmlstore .=”;

while($row_xmlw = mysql_fetch_array($result_xmlw)) {
$xmlstore .=”.$row_xmlw[‘image’].”;
$xmlstore .=”.$row_xmlw[‘thumbnail’].”;
$xmlstore .=’


$xmlstore .=”;

$xmlstore .=”;

$handle = fopen($xmlfile_path, ‘w’);

fwrite($handle, $xmlstore);

//Put XML file name and mysql table name simultaniously
writeXML(‘sample.xml’, ‘sampletable’);


3 thoughts on “Create XML file from mysql table

  1. Pingback: Bookmarks about Mysql

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s