2
11データベーステーブルのデータをXMLとしてエクスポートしようとしています。私は簡単に1つのテーブルを問題なくエクスポートすることができました。しかし、私は本当に複数を輸出しようとしています。複数のDBテーブルをSQLデータとしてエクスポートする
確かに、私は確かに別のテーブルエンティティとしてデータを出力します。どんな助けもこの1つで非常に高く評価されています。私はそれがちょっと難しいと思っています。
<?php
error_reporting(E_ALL);
$host = "localhost";
$user = "root";
$pass = "";
$database = "db_etch";
$table = "keywords";
$SQL_query = "SELECT * FROM $table";
$DB_link = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $DB_link) or die ("Could not find or access the database.");
$result = mysql_query ($SQL_query, $DB_link) or die ("Data not found. Your SQL query didn't work... ");
// produce XML
header("Content-type: text/xml");
$XML = "<?xml version=\"1.0\"?>\n";
// root node
$XML .= "<result>\n";
// rows
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$XML .= "\t<$table>\n";
$i = 0;
// cells
foreach ($row as $cell) {
$cell = str_replace("&", "&", $cell);
$cell = str_replace("<", "<", $cell);
$cell = str_replace(">", ">", $cell);
$cell = str_replace("\"", """, $cell);
$col_name = mysql_field_name($result,$i);
$XML .= "\t\t<" . $col_name . ">" . $cell . "</" . $col_name . ">\n";
$i++;
}
$XML .= "\t</$table>\n";
}
$XML .= "</result>\n";
// output the whole XML string
echo $XML;
// Write $sql to file
$File = "keywords.xml";
$fh = fopen($File, 'w') or die("can't open file");
$stringData = $XML;
fwrite($fh, $stringData);
fclose($fh);
?>
パーフェクト。ありがとう。配列のループを見ていたら、あなたの答えが出てきました。 – StuBlackett