mysql|xml
require_once "DB.php"; //PEAR中的数据库处理类
$dataType = "mysql" ; //数据库类型
$user = "root"; //用户名
$pass = "abcd" ; //密码
$host="202.96.215.200"; //Mysql数据库服务器地址
$db_name = "test"; //数据库名
$dsn="$dataType://$user:$pass@$host/$db_name"; //连接数据库的DNS配制
$db = DB::connect($dsn); //连接数据库
if (DB::isError($db))
{
die ($db->getMessage()); //连接失败,输出出错信息
}
//下面二个是公共的函数
/**
* 读取xsl文档
*
* @param String $filename - xsl文件的名称
* @return string
*/
function readXsl($filename)
{
if(false==file_exists($filename))
{
echo "要读取的文件$filename不存在/>";
return false ;
}
return implode('', file($filename));
} //end function readXsl
/**
* 将xml文件或数组变量根据xsl文件转换成HTML内容
*
* @param array $arydata - 数组变量
* @param String $xslstring - xsl文档数据
* @param String $xmlstring - xml文档数据
*/
function getHtml($arydata = false, $xslstring = false, $xmlstring = false)
{
global $db ; //使用刚才的$db对象
include_once("XML/sql2xml.php"); //把sql2xml包含进来
$sql2xmlclass = new xml_sql2xml($db); //将sql2xml实例化
$sql2xmlclass->setEncoding("GB2312"); //设置数据的转码类型
if (false == $xmlstring) { // 如果用户传入数组数据,则应用该数组数据到xsl
//设置生成XML文档数据的节点名称
$options = array ( tagNameRow => "row" ,
tagNameResult => "result"
);
$sql2xmlclass->SetOptions($options);
//添加要生成XML文档的数据
$sql2xmlclass->add($arydata);
}
//得到xml文档
$xmlstring = $sql2xmlclass->getxml();
//print $xmlstring;
//下面开始将XML数据文档用XSLT转换成HTML文档
$arguments = array('/_xml' => $xmlstring,
'/_xsl' => $xslstring
);
$xh = xslt_create();
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', null, $arguments);
if ($result) {
return $result;
xslt_free($xh);
} else {
return "转换xml数据到xsl时出错";
xslt_free($xh);
}
} //end function getHtml()
//从用户信息表中查询数据的SQL语句
$sql = "select
nsrnm, #代码
qymc, #企业名称
qydh #电话
from
yhxx #用户信息表";
// 执行SQL语句
$res = $db->query($sql);
if ($db->isError($res))
{
echo "执行SQL语句时出错";
}
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
{
$data[] = $row; //将数据放到一个数组中
}
//print_r($data);
//大家可以看到数据已经放到了一个多维的数组中了
//至此,我们的程序已经基本上完成了,再接下去,我们要定义显示数据的页面
//打开你的DW 或 FrontPage XP,制作显示的页面,我做了一个,并提供给大家下载
//我们制作的数据显示页面文件为:browesData.html
/*
这是我们平时要显示的数据列表界面

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
