Php, XML, XSLT, and Mysql are used in combination. For more information, see the use of php, XML, XSLT, and Mysql ,? Phprequire_once "> <LINKhref =" http://www.php100.com//statics/style/headfloor_950_081205.css "type = te
Require_once "DB. php"; // database processing class in PEAR
$ DataType = "mysql"; // Database type
$ User = "root"; // user name
$ Pass = "abcd"; // password
$ Host = "202.96.215.200"; // address of the Mysql database server
$ Db_name = "test"; // database name
$ Dsn = "$ dataType: // $ user: $ pass @ $ host/$ db_name"; // Configure the DNS for connecting to the database
$ Db = DB: connect ($ dsn); // connect to the database
If (DB: isError ($ db ))
{
Die ($ db-> getMessage (); // connection failed, error message output
}
// The following two are public functions.
/**
* Reading the xsl document
*
* @ Param String $ filename-xsl file name
* @ Return string
*/
Function readXsl ($ filename)
{
If (false = file_exists ($ filename ))
{
Echo "the file to be read $ filename does not exist
";
Return false;
}
Return implode ('', file ($ filename ));
} // End function readXsl
/**
* Convert xml files or array variables into HTML content based on the xsl file
* Http://knowsky.com
* @ Param array $ arydata-array variable
* @ Param String $ response String-xsl document data
* @ Param String $ xmlstring-xml document data
*/
Function getHtml ($ arydata = false, $ response string = false, $ xmlstring = false)
{
Global $ db; // use the $ db object
Include_once ("XML/sql2xml. php"); // include sql2xml
$ Sql2xmlclass = new xml_sql2xml ($ db); // instantiate sql2xml
$ Sql2xmlclass-> setEncoding ("GB2312"); // sets the data transcoding type.
If (false = $ xmlstring) {// if the user passes in the array data, apply the array data to the xsl
// Set the node name for generating XML document data
$ Options = array (tagNameRow => "row ",
TagNameResult => "result"
);
$ Sql2xmlclass-> SetOptions ($ options );
// Add the data to generate the XML document
$ Sql2xmlclass-> add ($ arydata );
}
// Obtain the xml document
$ Xmlstring = $ sql2xmlclass-> getxml ();
// Print $ xmlstring;
// Start to convert the XML data document to the HTML document using XSLT below
$ Arguments = array ('/_ XML' => $ xmlstring,
'/_ Xsl' => $ response string
);
$ Xh = effect_create ();
$ Result = effect_process ($ xh, 'Arg:/_ XML', 'Arg:/_ xsl ', null, $ arguments );
If ($ result ){
Return $ result;
Effect_free ($ xh );
} Else {
Return "an error occurred while converting xml data to xsl ";
Effect_free ($ xh );
}
} // End function getHtml ()
// SQL statement used to query data from the user information table
$ SQL = "select
Nsnm, # Code
Qymc, # company name
Qydh # phone number
From
Yhxx # User Information Table ";
// Execute the SQL statement
$ Res = $ db-> query ($ SQL );
If ($ db-> isError ($ res ))
{
Echo "an error occurred while executing SQL statements ";
}
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 multi-dimensional array.
// At this point, our program has basically been completed. Next, we need to define the page for displaying data.
// Open your DW or FrontPage XP and create the displayed page. I made one and provided it for you to download.
// The data display page file we created is browesData.html.
/*
This is the data list interface we usually want to display
Data browsing
Code |
Company name |
Phone Number |
|
|
|
*/
// I process it into an HTML document in XSLT format
/*
Data browsing
Code |
Company name |
Phone Number |
|
|
|
*/
$ HtmlFile = "browesData.html ";
$ HtmlStr = readXsl ($ htmlFile); // read HTML documents in xslt format to variables.
Echo getHtml ($ data, $ htmlStr );
// End the program
?>