Blog

Export data from mysql database to XML using php

Here is the simple code to do this export data from mysql database to XML using php.If you find the blank line at the top of your exported data. you need to remove the empty space on the php files. Now here you are with the code for exporting data from mysql database to XML using php

$result=mysql_query(“SELECT * FROM search_detail”);
//Start the xml file
$xmlData = ‘‘;
//Start the root element
$xmlData .=”“;

while ($row = mysql_fetch_assoc($result)) {
$xmlData.= ““;
$xmlData .=”“.$row['search_id'].”“;
$xmlData .=”“.$row['search_reference_id'].”“;
$xmlData .=”“.$row['search_contact_first_name'].”“;
$xmlData .=”“.$row['search_last_name'].”“;
$xmlData .=”“.$row['search_company'].”“;
$xmlData.= “
“;

}
//End the root element
$xmlData .=”“;
header(“Content-type: text/xml”);
header(‘Content-Disposition: attachment; filename=”text.xml”‘);
echo $xmlData;

Hope this does the work :)

This Post Has 0 Comments

Leave A Reply