test.php
<?
$db_host="localhost"; // Database address
$db_user="root"; // Database user name
$db_password="790511"; // Database password
$db_name="ultrax"; // Database name
$link=mysql_connect($db_host,$db_user,$db_password) or die("Connect database fail!");
//mysql_query("SET NAMES 'gb2312'",$link); // Select code type
$db=mysql_select_db($db_name,$link);
$table="pre_forum_post"; // Table name
$limit = $_GET['limit']; // Retreve variable "limit" for "get" mode
$start = $_GET['begin']; // Retreve variable "begin" for "get" mode
$maxcount = mysql_query("select * from $table");
$maxnum=mysql_numrows($maxcount);
$query ="select * from $table order by fid desc";
$result = mysql_query($query);
header('Content-Type: text/xml;');
$dom = new DOMDocument('1.0', 'utf-8'); // Using DOM component of PHP to create XML output
$root = $dom->createElement($db_name); // New a root node
$dom->appendChild($root);
$root->setAttribute('maxnum',$maxnum);
$elements =array();
$elementsesult = mysql_query("describe $table");
while ($elementsrow = mysql_fetch_array($elementsesult)) $elements[] = $elementsrow[0];
while ($row=mysql_fetch_array($result)) { // Create XML structure
$item = $dom->createElement($table);
$root->appendChild($item);
for ($j = 1; $j<count($elements) ; $j++){
$node = $dom->createElement($elements[$j]);
$item->appendChild($node);
$text = $dom->createTextNode($row[$elements[$j]]);
$node->appendChild($text);
}
}
$xmlString = $dom->saveXML(); // Save XML structure in a variable of string
echo $xmlString; // Output XML string
mysql_close($link); // Close connection to database
?>
test1.php
<?
include("extclass.php");
$db=new db();
echo $db->toExtXml('pre_common_usergroup');
?>