Zend - The PHP Company




XML

Add Code


create xml file/output from mysql database using php  

Type: application
Added by: mrmihir
Entered: 18/06/2002
Last modified: 06/12/2001
Rating: **** (5 votes)
Views: 16118
This program will display the XML output of your existing database in MySql. You can enhance it by using fopen and fput function to write the output in the file called xml one


<?php
//Developed by -==[Mihir Shah]==- during my Project work
//for the output
header("Content-type: text/xml");

//to create connection to database
$connection mysql_connect("127.0.0.1","username""password")
or die (
"could not connect to database");

//to select the database here test is the sample database come with mysql
$db mysql_select_db("test",$connection)
or die (
"Couldn't select database.");

$rs mysql_query("select * from tablename",$connection)
or die (
"invalid query");

//count the no. of  columns in the table
$fcount mysql_num_fields($rs);

//you can choose any name for the starting tag
echo ("<result>");
while(
$row mysql_fetch_array$rs ) )
{
echo (
"<tablerow>");
for(
$i=0$i$fcount$i++)
{
$tag mysql_field_name$rs$i );
echo (
"<$tag>"$row[$i]. "</$tag>");
}
echo (
"</tablerow>");
}
echo (
"</result>");
?>


Usage Example




Rate This Script





Search



This Category All Categories