View Full Version : Can you have an XML file created from a database using PHP

03-12-2010, 10:29 PM

I'm not sure this is possible but i have a flash video jukebox section on my site that has a tileList that is populated by an XML file. I would like to add the information to the XML file through a MySQL database using php if possible.
Right now i have this code that calls the information in the XML format but how do i get his to save as an XML file?


//XML output of an existing MySql database
header("Content-type: text/xml");

//to create connection to database
$connection = mysql_connect("localhost","root", "root")
or die ("could not connect to database");

//to select the database here
$db = mysql_select_db("motorsports",$connection)
or die ("Couldn't select database.");

$rs = mysql_query("select vid_desc, src, thumb FROM video_blog ORDER BY date_id DESC",$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 ("<playlist>");
while($row = mysql_fetch_array( $rs ) )

for($i=0; $i< $fcount; $i++)
$tag = mysql_field_name( $rs, $i );
echo ("<$tag>". $row[$i]. "</$tag>");

echo ("</playlist>");


Thanks in advance for any help you can give.


03-12-2010, 10:45 PM
Have a look at the SimpleXLMElement class: