I'm new to PHP and am trying to create a small snippet of code that reads the tables in my database and allows the user to download the tables into a CSV file.
So far, I've been able to connect to my database and echo through the tables
// 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();
?>
Now I'd like to turn each table into a link so when the user clicks on it, they will be able to download the table's data into a CSV file.
How do I do that?