PHP and XML, XSLT, MYSQL

xiaoxiao2021-03-06  94

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

Data Browse </ Title></p> <p></ hEAD></p> <p><body></p> <p><table border = "1" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse" bordercolor = "# 111111" width = "100%" id = "autonumber1"></p> <p><tr></p> <p><TD width = "21%" align = "center" bgcolor = "# c0c0c0"> code </ td></p> <p><td width = "50%" align = "center" bgcolor = "# c0c0c0"> Enterprise name </ td></p> <p><td width = "29%" align = "center" bgcolor = "# c0c0c0"> Phone </ td></p> <p></ TR></p> <p><tr></p> <p><td width = "21%"> </ td></p> <p><td width = "50%> </ td> <td width =" 29%> </ td></p> <p></ TR></p> <p></ table></p> <p></ body></p> <p></ html></p> <p>* /</p> <p>/ / I processed it into an HTML document in XSLT format.</p> <p>/ *</p> <p><? Xml Version = "1.0" Encoding = "??????"?></p> <p><XSL: Stylesheet Version = "1.0" XMLns: XSL = "http://www.w3.org/1999/xsl/transform"></p> <p><xsl> <img src = "images / smilies / redface.gif" border = "0" alt = "> UTPUT method =" HTML "Version =" 1.0 "eNCoding =" ?????? "" Indent = " Yes "/></p> <p><XSL: Template Match = "/"></p> <p><HEAD></p> <p><meta http-equiv = "content-type" content = "text / html; charSet = ??????" /></p> <p><Title> Data Browse </ Title></p> <p></ hEAD></p> <p><table border = "1" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse" bordercolor = "# 111111" width = "100%" id = "autonumber1"></p> <p><TBODY></p> <p><tr></p> <p><TD width = "21%" align = "center" bgcolor = "# c0c0c0"> code </ td></p> <p><td width = "50%" align = "center" bgcolor = "# c0c0c0"> Enterprise name </ td></p> <p><td width = "29%" align = "center" bgcolor = "# c0c0c0"> Phone </ td></p> <p></ TR></p> <p><xsl: for-each select = "root / result / row"></p> <p><tr></p> <p><TD Width = "21%> <XSL: Value-of SELECT =" nsrnm "/> </ td></p> <p><TD Width = "50%> <XSL: Value-of Select =" qymc "/> </ td></p> <p><td width = "29%"> <xsl: value-of select = "qydh" /> </ td> </ tr></p> <p></ xsl: for-energy></p> <p></ tbody></p> <p></ table></p> <p></ pre></p> <p>* /</p> <p>$ htmlfile = "browsdata.html";</p> <p>$ htmlstr = readxsl ($ htmlfile); // read the HTML document in the XSLT format to the variable</p> <p>Echo gethtml ($ DATA, $ HTMLSTR);</p> <p>// End of the program</p> <p>?></p> <p></ html></p> <p></ xsl: template></p> <p></ xsl: stylesheet></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-105099.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="105099" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'yuzFwW33DgzabwBs4GFhbWFVIcXP9CInyX_2FO5nsbYUhb0kOf3S_2B0eNu2VTTmqCj_2Fkg16_2BbBd5KE1l9zjO9esbA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>