私はPHPを初めて使い、データベースのテーブルを読み込んで、CSVファイルにテーブルをダウンロードできる小さなコードスニペットを作成しようとしています。データベース内のPHPエコーテーブルをCSVファイルとしてダウンロード
これまでのところ、私は今、私は、彼らは、ユーザーがそれをクリックしたときに、リンクに各テーブルを回すしたい私のデータベースに接続し、テーブルを通じて
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed1: " . $conn->connect_error);
}
// SQL query
$sql = "SHOW TABLES IN `abc1`";
// perform the query and store the result
$result = $conn->query($sql);
// if the $result not False, and contains at least one row
if($result !== false) {
// if at least one table in result
if($result->num_rows > 0) {
// traverse the $result and output the name of the table(s)
while($row = $result->fetch_assoc()) {
echo '<br />'. $row['Tables_in_abc1'];
}
}
else echo 'There is no table in "tests"';
}
else echo 'Unable to check the "tests", error - '. $conn->error;
$conn->close();
?>
をエコーすることができましたテーブルのデータをCSVファイルにダウンロードすることができます。
どうすればよいですか?