PHP로 SQL 데이터베이스를 구문 분석하여 XML을 출력 할 수 있기를 원하지만 테이블 이름과 모든 내용을 표시 할 수 없습니다. 나는 약간의 도움을 사용할 수있다. 여기에 로그인 정보가없는 코드가있다. 나는 db 서버, mdb 사용자와 패스 그리고 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