Mysql|xml <?php
Require_once "db.php"; Database processing classes in Pear
$dataType = "MySQL"; Database type
$user = "root"; User name
$pass = "ABCD"; Password
$host = "202.96.215.200"; MySQL Database server address
$db _name = "Test"; Database name
$DSN = "$dataType://$user: $pass @ $host/$db _name"; DNS Configuration of connection database
$db = Db::connect ($DSN); Connecting to a database
if (Db::iserror ($DB))
{
Die ($db->getmessage ()); Connection failed, output error message
}
The following two are public functions
/**
* Read the XSL document
*
* @param String $filename The name of the-xsl file
* @return String
*/
function readxsl ($filename)
{
if (false==file_exists ($filename))
{
echo "to read the file <font color= ' red ' > $filename </font> does not exist </br/>";
return false;
}
Return implode (', File ($filename));
}//end function readxsl
/**
* Convert an XML file or an array variable from an XSL file to an HTML content
*
* @param array $arydata-array variable
* @param String $xslstring-xsl document data
* @param String $xmlstring-xml document data
*/
function gethtml ($arydata = False, $xslstring = False, $xmlstring = False)
{
Global $db; Use just the $db object
Include_once ("xml/sql2xml.php"); To include Sql2xml in.
$sql 2xmlclass = new Xml_sql2xml ($DB); Instantiate the Sql2xml
$sql 2xmlclass->setencoding ("GB2312"); Set the type of transcoding for data
if (false = = $xmlstring) {//If the user passes in the array data, the array data is applied to the XSL
Set the node name for generating XML document data
$options = Array (tagnamerow => "Row",
Tagnameresult => "Result"
);
$sql 2xmlclass->setoptions ($options);
Add data to generate an XML document
$sql 2xmlclass->add ($arydata);
}
Get the XML document
$xmlstring = $sql 2xmlclass->getxml ();
Print $xmlstring;
The following begins converting an XML data document into an HTML document using XSLT
$arguments = Array ('/_xml ' => $xmlstring,
'/_xsl ' => $xslstring
);
$xh = Xslt_create ();
if ($result) {
return $result;
Xslt_free ($XH);
} else {
Return "error converting XML data to XSL";
Xslt_free ($XH);
}
}//end function gethtml ()
SQL statement that queries data from the User information table
$sql = "Select
NSRNM, #代码
QYMC, #企业名称
Qydh #电话
From
Yhxx #用户信息表 ";
Execute SQL statement
$res = $db->query ($sql);
if ($db->iserror ($res))
{
echo "Error executing SQL statement";
}
while ($row = $res->fetchrow (DB_FETCHMODE_ASSOC))
{
$data [] = $row; Put the data in an array
}
Print_r ($data);
You can see that the data has been placed in a multidimensional array.
At this point, our program has been basically completed, and then, we want to define the page to display the data
Open your DW or FrontPage XP, make the displayed page, I made one, and provide to everyone to download
We produced the data display page file as: browesdata.html
/*
This is the data listing interface we're going to display.
<meta http-equiv= "Content-language" content= "ZH-CN" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Data Browsing </title>
*/
$htmlFile = "browesdata.html";
$HTMLSTR = readxsl ($htmlFile); To read an HTML document in XSLT format into a variable
Echo gethtml ($data, $HTMLSTR);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.