【发布时间】:2017-03-09 23:04:25
【问题描述】:
我是 PHP 新手,我正在尝试创建一个小的 sn-p 代码来读取我数据库中的表并允许用户将表下载到 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 文件中。
我该怎么做?
【问题讨论】:
标签: php database csv hyperlink