当前位置: 编程技术>php
本页文章导读:
▪把从SQL中取出的数据转化成XMl格式
使用了php的PEAR和DB<?php// +----------------------------------------------------------------------+// | PHP version 4.0 .........
▪JAVA/JSP学习系列之四
一、前言 Orion这个东西,小巧,但是功能却非常多,废话不讲,看它目前的支持就知道了: (1)Servlets/JSP (2)EJB (3)HTTP (注:说明不再需要Apache或者IIS等Web Server) 二、下载,.........
▪JAVA/JSP学习系列之二
一、前言 对于初学者来说,要执行JSP和Servlet,Tomcat是一个很不错的选择,。Tomcat是Apache组织的产品,sun公司对它的支持也相当不错。 二、下载,安装 下载地址为JAVA官.........
[1]把从SQL中取出的数据转化成XMl格式
来源: 互联网 发布时间: 2013-11-30
使用了php的PEAR和DB
<?php
// +----------------------------------------------------------------------+
// | PHP version 4.0
|// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group
|// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license,
|// | that is bundled with this package in the file LICENSE, and is
|// | available at through the world-wide-web at
|// | http://www.php.net/license/2_02.txt.
|// | If you did not receive a copy of the PHP license and are unable to
|// | obtain it through the world-wide-web, please send a note to
|// | license@php.net so we can mail you a copy immediately.
|// +----------------------------------------------------------------------+
// | Authors: Christian Stocker <chregu@phant.ch>
|// +----------------------------------------------------------------------+
//
// $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
/**
* This class takes a PEAR::DB-Result Object, a sql-query-string or an array
* and returns a xml-representation of it.
*
* TODO
* -encoding etc, options for header
* -ERROR CHECKING
*
* Usage example
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $db = DB::connect("mysql://root@localhost/xmltest");
* $sql2xml = new xml_sql2xml();
* //the next one is only needed, if you need others than the default
* $sql2xml->setEncoding("ISO-8859-1","UTF-8");
* $result = $db->query("select * from bands");
* $xmlstring = $sql2xml->getXML($result);
*
* or
*
* include_once ("DB.php");
* include_once("XML/sql2xml.php");
* $sql2xml = new xml_sql2xml("mysql://root@localhost/xmltest");
* $sql2xml->Add("select * from bands");
* $xmlstring = $sql2xml->getXML();
*
* More documentation and a tutorial/how-to can be found at
* http://php.chregu.tv/sql2xml
*
* @author Christian Stocker <chregu@bitflux.ch>
* @version $Id: sql2xml.php,v 1.59 2001/11/13 10:54:02 chregu Exp $
* @package XML
*/
class XML_sql2xml {
/**
* If joined-tables should be output nested.
* Means, if you have joined two or more queries, the later
* specified tables will be nested within the result of the former
* table.
* Works at the moment only with mysql automagically. For other RDBMS
* you have to provide your table-relations by hand (see user_tableinfo)
*
* @var boolean
* @see $user_tableinfo, doSql2Xml(), doArray2Xml();
*/
var $nested = True;
/**
* Name of the tag element for resultsets
*
* @var string
* @see insertNewResult()
*/
var $tagNameResult = "result";
/**
* Name of the tag element for rows
*
* @var string
* @see insertNewRow()
*/
var $tagNameRow = "row";
/**
*
* @var object PEAR::DB
* @access private
*/
var $db = Null;
/**
* Options to be used in extended Classes (for example in sql2xml_ext).
* They are passed with SetOptions as an array (arrary("user_options" = array());
* and can then be accessed with $this->user_options["bla"] from your
* extended classes for additional features.
* This array is not use in this base class, it's only for passing easy parameters
* to extended classes.
*
* @var array
*/
var $user_options = array();
/**
* The DomDocument Object to be used in the whole class
*
* @var object DomDocument
* @access private
*/
var $xmldoc;
/**
* The Root of the domxml object
* I'm not sure, if we need this as a class variable....
* could be replaced by domxml_root($this->xmldoc);
*
* @var object DomNode
* @access private
*/
var $xmlroot;
/**
* This array is used to give the structure of your database to the class.
* It's especially useful, if you don't use mysql, since other RDBMS than
* mysql are not able at the moment to provide the right information about
* your database structure within the query. And if you have more than 2
* tables joined in the sql it's also not possible for mysql to find out
* your real relations.
* The parameters are the same as in fieldInfo from the PEAR::DB and some
* additional ones. Here they come:
* From PEAR::DB->fieldinfo:
*
* $tableInfo[$i]["table"] : the table, which field #$i belongs to.
* for some rdbms/comples queries and with arrays, it's impossible
* to find out to which table the field actually belongs. You can
* specify it here more accurate. Or if you want, that one fields
* belongs to another table, than it actually says (yes, there's
* use for that, see the upcoming tutorial ...)
*
* $tableInfo[$i]["name"] : the name of field #$i. if you want another
* name for the tag, than the query or your array provides, assign
* it here.
*
* Additional info
* $tableInfo["parent_key"][$table] : index of the parent key for $table.
* this is the field, where the programm looks for changes, if this
* field changes, it assumes, that we need a new "rowset" in the
* parent table.
*
* $tableInfo["parent_table"][$table]: name of the parent table for $table.
*
* @var array
* @access private
*/
var $user_tableInfo = array();
/**
* the encoding type, the input from the db has
*/
var $encoding_from = "ISO-8859-1";
/**
* the encoding type, the output in the xml should have
* (note that domxml at the moment only support UTF-8, or at least it looks like)
*/
var $encoding_to = "gb2312";
var $tagname = "tagname";
/**
* Constructor
* The Constructor can take a Pear::DB "data source name" (eg.
* "mysql://user:passwd@localhost/dbname") and will then connect
* to the DB, or a PEAR::DB object link, if you already connected
* the db before.
" If you provide nothing as $dsn, you only can later add stuff with
* a pear::db-resultset or as an array. providing sql-strings will
* not work.
* the $root param is used, if you want to provide another name for your
* root-tag than "root". if you give an empty string (""), there will be no
* root element created here, but only when you add a resultset/array/sql-string.
* And the first tag of this result is used as the root tag.
*
* @param mixed $dsn PEAR::DB "data source name" or object DB object
* @param string $root the name of the xml-doc root element.
* @access public
*/
function XML_sql2xml ($dsn = Null, $root = "root") {
// if it's a string, then it must be a dsn-identifier;
if (is_string($dsn))
{
include_once ("DB.php");
$this->db = DB::Connect($dsn);
if (DB::isError($this->db))
{
print "The given dsn for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."<br>\n";
return new DB_Error($this->db->code,PEAR_ERROR_DIE);
}
}
elseif (is_object($dsn) && DB::isError($dsn))
{
print "The given param for XML_sql2xml was not valid in file ".__FILE__." at line ".__LINE__."<br>\n";
return new DB_Error($dsn->code,PEAR_ERROR_DIE);
}
// if parent class is db_common, then it's already a connected identifier
elseif (get_parent_class($dsn) == "db_common")
{
$this->db = $dsn;
}
$this->xmldoc = domxml_new_xmldoc('1.0');
//oehm, seems not to work, unfortunately.... does anybody know a solution?
$this->xmldoc->encoding = $this->encoding_to;
if ($root) {
$this->xmlroot = $this->xmldoc->add_root($root);
//PHP 4.0.6 had $root->name as tagname, check for that here...
if (!isset($this->xmlroot->{$this->tagname}))
{
$this->tagname = "name";
}
}
}
/**
* General method for adding new resultsets to the xml-object
* Give a sql-query-string, a pear::db_result object or an array as
* input parameter, and the method calls the appropriate method for this
* input and adds this to $this->xmldoc
*
* @param string sql-string, or object db_result, or array
* @param mixed additional parameters for the following functions
* @access public
* @see addResult(), addSql(), addArray(), addXmlFile()
*/
function add ($resultset, $params = Null)
{
// if string, then it's a query, a xml-file or a xml-string...
if (is_string($resultset)) {
if (preg_match("/\.xml$/",$resultset)) {
$this->AddXmlFile($resultset,$params);
}
elseif (preg_match("/.*select.*from.*/i" , $resultset)) {
$this->AddSql($resultset);
}
else {
$this->AddXmlString($resultset);
}
}
// if array, then it's an array...
elseif (is_array($resultset)) {
$this->AddArray($resultset);
}
if (get_class($resultset) == "db_result") {
$this->AddResult($resultset);
}
}
/**
* Adds the content of a xml-file to $this->xmldoc, on the same level
* as a normal resultset (mostly just below <root>)
*
* @param string filename
* @param mixed xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result
* @access public
* @see doXmlString2Xml()
*/
function addXmlFile($file,$xpath = Null)
{
$fd = fopen( $file, "r" );
$content = fread( $fd, filesize( $file ) );
fclose( $fd );
$this->doXmlString2Xml($content,$xpath);
}
/**
* Adds the content of a xml-string to $this->xmldoc, on the same level
* as a normal resultset (mostly just below <root>)
*
* @param string xml
* @param mixed xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result
* @access public
* @see doXmlString2Xml()
*/
[2]JAVA/JSP学习系列之四
来源: 互联网 发布时间: 2013-11-30
一、前言
Orion这个东西,小巧,但是功能却非常多,废话不讲,看它目前的支持就知道了:
(1)Servlets/JSP
(2)EJB
(3)HTTP (注:说明不再需要Apache或者IIS等Web Server)
二、下载,安装
下载地址为Orion Application Server官方站点:http://www.orionserver.com/,我下载的是Orion1.4版本。
下载完,解压到一个目录,我这里用E:Orion作为例子。
三、配置
(1)根据Orion官方站点的安装说明,如果要支持JSP等技术的话,要将JDK的tools.jar复制到e:orion目录下,tools.jar文件在你安装的JDK目录的lib子目录下。
到现在,其实已经成功了缺省的配置了,如果你的80端口没有被占用,而且你也想用80作为端口的话,你到这里已经完成了,否则,请继续下面的配置。
(2)配置端口
在E:orionconfig目录下有个default-web-site.xml文件,找到文件中下面行:
将这行改为:
注意,我这里使用的是8008端口。
四、测试
(1)启动Orion:
在Orion目录下,command方式运行:
java -jar orion.jar
将出现Orion/x.x.x initialized,我这里版本是1.4所以显示:
Orion/1.4.0 initialized
到此,说明你已经成功了。
(2)执行jsp文件
在浏览器中输入:
http://localhost:8008/
出现:Orion Application Server 1.4.0 - Up and running,下面有JSP examples你可以试着运行。(出处:viphot.com)
[3]JAVA/JSP学习系列之二
来源: 互联网 发布时间: 2013-11-30
一、前言
对于初学者来说,要执行JSP和Servlet,Tomcat是一个很不错的选择,。Tomcat是Apache组织的产品,sun公司对它的支持也相当不错。
二、下载,安装
下载地址为JAVA官方站点:jakarta.apache.org,国内也比较多。
从这个地址可以下载:http://jakarta.apache.org/builds/tomcat/release/,我下载的是Tomcat32b4版本。
下载完,解压到一个目录,我这里用F: omcat32b4作为例子。
三、配置
桌面上选择“我的电脑”(右键)
高级
环境变量
在“系统变量”--->“新建”
在变量名中输入:JAVA_HOME,变量值中输入:F:JDK13然后确定;
在“系统变量”--->“新建”
在变量名中输入:TOMCAT_HOME,变量值中输入:F: omcat32b4然后确定;
好了,配置完了,要重新启动计算机后,环境变量才能有效的。
注意,对于Tomcat其他设置,如果没有必要,是可以不改的,我这里讲的都是最简单而可行的方法,如果对你的改动没有把握,还是建议不要改动。
四、测试
(1)启动tomcat:
在F: omcat32b4in下有一个:startup.bat,运行它,将出现一个Dos窗口。
(2)浏览
在浏览器中输入:http://localhost:8080/看看有什么效果(Tomcat默认端口为8080,在不冲突的前提下,你可以改动的),是不是可以看到一只可爱的小猫(其实,我个人认为,无论从颜色还是样子,更象一只老虎)
(3)运行
在这个页面有JSP Examples和 Servlet Examples, 好了,自己测试运行它们吧。
(4)退出tomcat
在F: omcat32b4in下有一个:shutdown.bat,运行它,将关闭Dos窗口(如果坚持直接关闭这个DOS窗口也是可以的,但是,既然有这个shutdown.bat,应该有它存在的理由)。(出处:viphot.com)
最新技术文章: