gpt4 book ai didi

php - 使用 PHP 脚本将 MySQL 转换为 XML

转载 作者:行者123 更新时间:2023-11-29 10:50:50 25 4
gpt4 key购买 nike

我遇到过这样的情况:我正在运行 PHP 脚本,以便将 MYSQL 数据库的内容输出到 XML。由于某种原因,下面的代码为数据库的前 7 行生成了所需的结果,然后失败并出现以下错误:

This page contains the following errors: error on line 1 at column 860: Encoding error

下面是出现第一个错误之前的页面呈现。”

(我使用“ID”列作为引用)

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysqli_query($database, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
// Add to XML document node
echo '<marker ';
echo 'id="' . $ind . '" ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}

// End XML file
echo '</markers>';

此处所需的输出是:

<markers>
<marker id="1" name="xxx" address="xxx" lat="xxx" lng="xxx" type="xxx"/>
<marker id="2" name="xxx" address="xxx" lat="xxx" lng="xxx" type="xxx"/>
...
</markers>

盯着这个看了几个小时,我似乎无法弄清楚,希望另一双眼睛看看,因为我认为代码不一定有什么问题,但想知道是否有实现的方法有一些限制吗?

提前感谢大家,祝你有美好的一天😊

最佳答案

这段代码可以很好地使用 PHP 将 MYSQL 转换为 XML,但是按照 Steve 在评论中的建议,第 8 行有一个错误。 friend 们,请务必检查您的撇号。

关于php - 使用 PHP 脚本将 MySQL 转换为 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43762989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com