加载xml文件失败
上面是出错信息,不知道怎么回事,我写了个DTD文件和XML文件,保存为UTF-8编码,可关掉后再打开又变成ANSI,新建文件重新写也是一样,求解。
dtd文件如下:
xml文件如下:
SqlTool.class.php文件:
class SqlTool{
private $link;
private $host;
private $username;
private $password;
private $dbname;
public function __construct(){
$doc=new DOMDocument();
if(!$doc->load("db.xml")){
die("加载xml文件失败");
}
$xpath=new DOMXPath($doc);
$this->host=$xpath->query("//host")->item(0)->nodeValue;
$this->username=$xpath->query("//username")->item(0)->nodeValue;
$this->password=$xpath->query("//password")->item(0)->nodeValue;
$this->dbname=$xpath->query("//dbname")->item(0)->nodeValue;
$this->link=new mysqli($this->host, $this->user, $this->password, $this->database);
if ($this->link->connect_error) {
die('连接数据失败('.$this->link->connect_errno.')'.$this->link->connect_error);
}
$this->link->set_charset($link, "utf-8");
}
}
?>
我用test.php测试就出现问题:
test.php代码:
header("content-type:text/html;charset=utf-8");
require_once './tools/SqlTool.class.php';
$link=new SqlTool();
if ($link) {
echo "测试连接成功";
}else {
echo "测试连接失败";
}
?>