我希望能夠用PHP解析SQL數據庫來輸出XML,但是我不能讓它顯示錶名和它的所有內容。我可以使用一些幫助,這裏是我的代碼沒有登錄信息: 我已經定義了db服務器,mdb用戶和pass以及db名稱;應該定義什麼?PHP XML解析問題
<?php
// connection to the database
$dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS)
or die("Unable to connect to MySQL");
// select a database to work with
$selected = mysql_select_db(DB_NAME, $dbhandle)
or die("Could not select data");
// return all available tables
$result_tbl = mysql_query("SHOW TABLES FROM "DB_NAME, $dbhandle);
$tables = array();
while ($row = mysql_fetch_row($result_tbl)) {
$tables[] = $row[0];
}
$output = "<?xml version=\"1.0\" ?>\n";
$output .= "<schema>";
// iterate over each table and return the fields for each table
foreach ($tables as $table) {
$output .= "<table name=\"$table\">";
$result_fld = mysql_query("SHOW FIELDS FROM "$table, $dbhandle);
while($row1 = mysql_fetch_row($result_fld)) {
$output .= "<field name=\"$row1[0]\" type=\"$row1[1]\"";
$output .= ($row1[3] == "PRI") ? " primary_key=\"yes\" />" : " />";
}
$output .= "</table>";
}
$output .= "</schema>";
// tell the browser what kind of file is come in
header("Content-type: text/xml");
// print out XML that describes the schema
echo $output;
// close the connection
mysql_close($dbhandle);
?>
什麼不起作用? – hakre
我得到表名,但沒有顯示任何內容。 – JAckie