我是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文件中。
我該怎麼做?