日期:2014-05-16 浏览次数:20386 次
<?xml version="1.0" encoding="utf-8"?>
<mysql_parameter>
<mysql>
<servicer>localhost</servicer>
<root>root</root>
<pw>123</pw>
</mysql>
</mysql_parameter>
以上是xml类型的mysql配置文件
<?php
$doc=new DOMDocument('1.0','utf-8');
$doc->load("mysql_xml.xml");
$mysql=$doc->getElementsByTagName("mysql");
$mysql1=$mysql->item(0);
$servicer=$mysql1->getElementsByTagName("servicer")->item(0)->nodeValue;
//echo $servicer;
$root=$mysql1->getElementsByTagName("root")->item(0)->nodeValue;
//echo $root;
$pw=$mysql1->getElementsByTagName("pw")->item(0)->nodeValue;
//echo $pw;
$link=mysql_connect("$servicer","$root","$pw")or die('连接数据库失败');
mysql_select_db('user',$link) or die('失败');
$sql='select *from usertable;';
$res=mysql_query($sql);
while($rows=mysql_fetch_row($res)){
foreach($rows as $value)
{echo $value;}
}