<?php
class Xml
{
var $xop;
private
function KeyName
(array $a,
$pos)
{
$temp =
array_slice($a,
$pos,
1,
true);
return key($temp);
}
public
function dbtoXml
($host,
$user,
$pass,
$dbname,
$tblname)
{
$connection =
mysql_connect($host,
$user,
$pass) or
die("Could not connect.");
$db =
mysql_select_db($dbname,
$connection);
$qry =
"select * from " .
$tblname;
$result =
mysql_query($qry,
$connection) or
die("Could not complete database query");
$this->
xop=
"<?xml version=\"1.0\" ?>\n";
$this->
xop.=
"<root>\n";
$i=
0;
$keyarray=
array();
while($at=
mysql_fetch_assoc($result))
{
$keyarray[]=
$this->
KeyName($at,
$i);
$i++;
}
array_pop($keyarray);
$result =
mysql_query($qry,
$connection) or
die("Could not complete database query");
while($a=
mysql_fetch_array($result))
{
$i=
0;
$this->
xop.=
"<content>\n";
for($j=
0;
$j<count
($keyarray);
$j++
)
{
$this->
xop.=
"<".
$keyarray[$j].
">".
$a[$i].
"</".
$keyarray[$j].
">".
"\n";
$i++;
}
$this->
xop.=
"</content>\n";
}
$this->
xop.=
"</root>";
}
public
function showXml
()
{
return $this->
xop;
}
}//end class
?>