Sometimes it's nice to mix up data storage types. This is a very simple SQL to XML converter. Feed it a SQL query and it outputs the result in XML.
The first paramater should be a mysql_query result
(optional)The second is the xml name for each row (i.e the second depth of XML)
(optional)The third is the name of the XML document, the root name
<?php
$result=mysql_query("SELECT * FROM users");
sql_to_xml($result,"users","members");
function sql_to_xml($mysql_result,$row_name="row",$doc_name="root")
{
$xml= new SimpleXMLElement("<$doc_name></$doc_name>");
while($line=mysql_fetch_assoc($mysql_result))
{
$row=$xml->addChild($row_name);
foreach($line as $column => $value)
{
$row->$column="$value";
}
}
return $xml->asXML();
}
?>