{code class="brush:php"}
header("Content-type: text/xml");
$mysqli = new mysqli($db_host, $db_user, $db_password, $db);
if ($mysqli->connect_error) {
die('Fallo al conectar con MySQL (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$query = "SELECT * FROM " . $table;
/* @var $result mysqli_result */
$result = $mysqli->query($query);
$col_info = $result->fetch_fields();
echo "<data>\n";
while ($row = $result->fetch_row()) {
echo "<row>\n";
$num_cols = count($row);
for ($i = 0; $i < $num_cols; $i++) {
echo "<" . $col_info[$i]->name . ">";
echo $row[$i];
echo "</" . $col_info[$i]->name . ">\n";
}
echo "</row>\n";
}
echo "</data>";
$result->free();
$mysqli->close();
{/code}