我以为我是从mysql查询中在我的php脚本中正确创建了一个xml文档,但我没有得到一个xml文档作为回报(没有php错误来帮助我),即使mysql查询有效!
<?php
...
$result = $mysqli->query($sql);
if ($result) { //this query works, but no xml document produced as a result
$d = new DOMDocument();
$books = $d->createElement('hey');
$hey->setAttribute('check','The Adventures of Tom Sawyer');
$d->appendChild($books);
$d->appendChild($hey);
$d->appendChild($books);
echo $d->saveXML();
}
?>
答案 0 :(得分:2)
$d->setAttribute('check','The Adventures of Tom Sawyer');
$ d“是”DOMDocument对象,没有DOMDocument :: setAttribute()方法。
使用DOMElement::setAttribute()或DOMDocument::createAttribute()
if ($result) {
$d = new DOMDocument();
$books = $d->createElement('hey');
$books->setAttribute('check','The Adventures of Tom Sawyer');
$d->appendChild($books);
echo $d->saveXML();
}