PHP and XML, XSLT, MYSQL
Author: xiaocon
Add time: 2003-11-26
Views: 248
Author: xiaocon
Mailbox: xiaocon@21cn.com
Please indicate the source
One PHP and XML, XSLT, MYSQL combination, installation articles
I often see that some users ask about PHP and XML, the database combined with the database, often see some beginners
Mix the PHP code with the HTML code together, then can't find a mistake at an error, anxious group turn, I will give it below.
At home, how to separate HTML code and PHP programs in XML technology, of course, there are many kinds of technologies, such as PEAR
IT template.
In general, individuals believe that using XML technology is the most convenient, nonsense, we have said, our words retired,
Speaking of the installation under Win2000
Use the XML and XSLT in PHP to use some DLL libraries,
Extension = php_domxml.dll // Operation XML function library
Extension = php_iconv.dll // Transcoding, such as transferred to UTF-8 in ??????
Extension = php_xslt.dll // xslt's Library
When using the above three libraries, you have to join the DLLS directory in the PHP installation directory to the path, otherwise you will not find
These class libraries
In the following courses, we will use the PEAR class library in the PHP, mainly used the DB class library, SQL2XML class, everyone can
Pear.php.net downloads the latest version
After downloading the two class libraries above, everyone is best to set up in php.ini.
INCLUDE_PATH = ".; D: / PHP / PEAR"
D: / PHP / PEAR is my PEAR installation path
After setting, restart the machine, otherwise, because the path is not found, the Apache is not started abnormal, and it cannot be used.
At this time, it is very simple to use XML and XSLT settings in PHP.
Users who use Linux can go
Http://www.gingerall.com/ Download the source code for XSLT
http://www.gnu.org/software/libicon ... About ICONV source code
The combination of two PHP and XML, XSLT, Mysql, primary articles
Below I am going to talk about data from the database, generate an XML document, and use XSLT to convert to HTML process,
This process only uses the process of using this technology, and does not involve other technologies such as paging.
This example I use the following database tables and data
Name: Enterprise User Information Table, English Name: YHXX
Table Structure:
#
# 数据 数据 结构 结构 ```
#
Create Table Yhxx
nsrnm varchar (15) Not null default '',
qymc varchar (200) Not null default '',
qydh varchar (50) Not null default ',
Primary Key (NSRNM)
) TYPE = Myisam Comment = 'User Information Table';
#
# 数据 数据 内容 内容 `yhxx`
#
INSERT INTO YHXX VALUES ('310109040111985 ",' Qiaojia Food Development Co., Ltd. ',' 8621-63346626 ');
INSERT INTO YHXX VALUES ('310104040221736 ",' Shanghai Jialing Trading Co., Ltd. ',' 74292546 '); Insert Into Yhxx Values (' 310108040331576", 'Jade Art Company', '54861465');
Next, I start writing the program that extracts the data and the page displayed data.
In order to make everyone understand, I use the easiest way to write the program.
Program file name: browesdata.php
Page file name: browesdata.html
Program and page files provide downloads, this program has been tested under Win2000, MySQL
See the next page of the code
If you are interested in this technology, I will tell you about PHP and XML, XSLT, database combination and more steps.
?>
GetMessage ()); / / Connection failed, output error information
}
// The following is a common function
/ **
* Read the XSL document
*
* @Param string $ filename - Name of XSL file
* @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 file or array variable to HTML content according to XSL files
*
* @Param Array $ AryData - an array variable
* @Param string $ xslstring - XSL document data
* @Param string $ xmlstring - XML document data
* /
Function gethtml ($ AryData = False, $ Xslstring = false, $ xmlstring = false)
{
Global $ db; // Using the $ db object just now
INCLUDE_ONCE ("XML / SQL2XML.PHP"); // Putting SQL2XML into
$ SQL2XMLCLASS = New XML_SQL2XML ($ dB); // Install SQL2XML
$ SQL2XMLCLASS-> setEncoding ("??????"); // Setting the transcodation type of the data
If (false == $ xmlstring) {// If the user passes an array data, the array data is applied to XSL.
/ / Set the node name to generate XML document data
$ options = array (tagnamerow => "row",
Tagnameresult => "result"
);
$ SQL2XMLCLASS-> SetOptions ($ OPTIONS);
// Add data to generate an XML document
$ SQL2XMLCLASS-> Add ($ ARYDATA);
}
// Get an XML document
$ xmlstring = $ sql2xmlclass-> getXML ();
// Print $ xmlstring;
/ / The following starts to convert the XML data document with XSLT to HTML documentation
$ arguments = array ('/ _ xml' => $ xmlstring,
'/ _xsl' => $ xslstring
);
$ xh = xslt_create (); $ r = xslt_process ($ xh, 'arg: / _ xml', 'arg: / _ xsl', null, $ arguments);
IF ($ result) {
Return $ Result;
XSLT_FREE ($ XH);
} else {
Return "Convert XML Data to XSL Error";
XSLT_FREE ($ XH);
}
} // end function gethtml ()
/ / Query data from the user information table SQL statement
$ SQL = "SELECT
Nsrnm, # code
QYMC, # 企业 企业 名
QYDH # phone
From
YHXX # User Information Table ";
/ / Execute SQL statement
$ RES = $ DB-> Query ($ SQL);
IF ($ DB-> ISERROR ($ RES))
{
Echo "error when performing SQL statement";
}
While ($ row = $ r-> fetchrow (db_fetchmode_assoc))
{
$ Data [] = $ row; // Put the data in an array
}
// Print_R ($ DATA);
// Everyone can see that the data has been put in a multi-dimensional array.
/ / To this, our program has been basically completed, then it will be, we want to define the page displayed
// Open your DW or FrontPage XP, make a displayed page, I have done one and provide to everyone to download
// We make data display page files: browesdata.html
/ *
This is the data list interface we usually display
hEAD>