0

我认为我从 mysql 查询中正确地在我的 php 脚本中创建了一个 xml 文档,但是即使 mysql 查询有效,我也没有得到一个 xml 文档作为回报(没有 php 错误可以帮助我)!

    <?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();
}
    ?>
4

1 回答 1

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();
}
于 2012-11-09T08:26:04.393 回答