Hi,
Let me clear about your problem..
Whether you want to retrieve data from MySQl or some other RDBMS?
If you are using MySQL for storing data then it's quite simple ..
I got it from net..
//mysql2xml.php
class mysql2xml {
var $sHost = "localhost";
var $sUser = "root";
var $sPass = "secret";
var $sDb = "urDB";
var $sSql;
function mysql2xml($sDb,$sSql) {
$this->sDb = $sDb;
$this->sSql = $sSql;
}
function connect() {
mysql_connect($this->sHost,$this->sUser,$this->sPass);
mysql_select_db($this->sDb);
}
function getXml() {
$this->connect();
$iRes = mysql_query($this->sSql);
if(!mysql_num_rows($iRes)) {
return "EMPTY";
} else {
$iNumFields = mysql_num_fields($iRes);
$iNumRes = mysql_num_rows($iRes);
$sRet = "<?xml version=\"1.0\"?>\n";
$sRet .= "<RESULTSET COUNT=\"$iNumRes\">\n";
while($iRow = mysql_fetch_array($iRes)) {
$sRet .= " <RESULT>\n";
for($a = 0; $a < $iNumFields; $a++) {
$sTmp = mysql_field_name($iRes,$a);
$sRet .= " ".strtoupper("<$sTmp>");
$sRet .= $iRow["$sTmp"];
$sRet .= strtoupper("</$sTmp>")."\n";
}
$sRet .= " </RESULT>\n";
}
$sRet .= "</RESULTSET>\n";
return $sRet;
}
}
}
$sSql = "SELECT * FROM user_profile";
$oXml = new mysql2xml("HPM",$sSql);
$x = $oXml->getXml();
echo $x;
?>
--Shastry