<?php
error_reporting(0);
$servername = "127.0.0.1";
$username = "bb";
$password = "EfNfi5H4JNTxGZfR";
$dbname = "bb";
if (isset($_POST['delete'])) {
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $tables = $conn->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
        foreach ($tables as $table) {
            $stmt = $conn->prepare("DROP TABLE $table");
            if ($stmt->execute()) {

            } else {

            }
        }
        echo "<script>window.location.href='./';</script>";
    } catch (PDOException $e) {
        echo "连接失败:". $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>删除所有数据表</title>
</head>
<body>
    <h1>删除所有数据表</h1>
    <form method="post">
        <button type="submit" name="delete">删除所有数据表</button>
    </form>
</body>
</html>
最后修改:2023 年 11 月 18 日
如果觉得我的文章对你有用,请随意赞赏