我的网站上有一个 MySQL 数据库,我想知道如何通过 PHP 从名为“customers”的表中获取请求的 XML 输出。
我有这个代码,它可以工作,但我想命名一个客户并只给我这个。
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eshop");
$query = "select name,address from customer";
$res = mysql_query($query);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('customers');
while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("customer");
$xml->writeAttribute('name', $row['name']);
$xml->writeAttribute('address', $row['address']);
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
?>
如果您能告诉我该怎么做,我将不胜感激。请注意; 我是 PHP 的新手!