Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/slutprojekt/

drop.php
include/
login.php
signin.php
start.php
tabeller/
verify.php

drop.php

27 lines ASCII Windows (CRLF)
<?php
include ('../../dbconnection.php');

try {


    
$pdo->exec('SET FOREIGN_KEY_CHECKS = 0;');
    
    
$stmt $pdo->query("SELECT table_name FROM information_schema.tables WHERE table_schema = '$dbname'");
    
$tables $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    
// Step 3: Drop each table
    
foreach ($tables as $table) {
        
$table_name $table['table_name'];
        
$pdo->exec("DROP TABLE IF EXISTS `$table_name`;");
        echo 
"Table `$table_name` dropped successfully.<br>";
    }
    
    
// Step 4: Re-enable Foreign Key Checks
    
$pdo->exec('SET FOREIGN_KEY_CHECKS = 1;');
    
    echo 
"All tables dropped successfully!";
} catch (
PDOException $e) {
    echo 
"Error: " $e->getMessage();
}
?>