97 lines
3.3 KiB
PHP
97 lines
3.3 KiB
PHP
|
<!DOCTYPE html>
|
||
|
|
||
|
<html>
|
||
|
|
||
|
<head>
|
||
|
<meta charset="UTF-8" />
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||
|
<link rel="stylesheet" href="db_management.css" />
|
||
|
<!-- <script src="trojan.js"></script>-->
|
||
|
<title>no title</title>
|
||
|
</head>
|
||
|
|
||
|
<body class="sqlOutput">
|
||
|
<?php
|
||
|
// USER-DEFINED VARIABLES
|
||
|
include("../dev_db_config.php"); // Include database stuff
|
||
|
|
||
|
|
||
|
try { // Try opening the SQL database connection
|
||
|
$conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password);
|
||
|
// set the PDO error mode to exception
|
||
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||
|
echo "<p>Connected successfully</p>";
|
||
|
} catch (PDOException $e) { // failed connection
|
||
|
echo "Connection failed: " . $e->getMessage();
|
||
|
}
|
||
|
|
||
|
// Check if the users table exists already
|
||
|
$sqlCheckUserTable = $conn->prepare("SHOW TABLES LIKE '" . $userTableName . "'");
|
||
|
|
||
|
// Run the query
|
||
|
$sqlCheckUserTable->execute();
|
||
|
|
||
|
//Check if any rows exist - if not, create the table, if yes, destroy it first, then create it
|
||
|
$count = $sqlCheckUserTable->rowCount();
|
||
|
|
||
|
if ($count != 0) {
|
||
|
echo "<p>Deleting exsiting table '" . $userTableName . "'...</p>";
|
||
|
// Create the query to drop the table
|
||
|
$sqlDropUserTable = "DROP TABLE " . $userTableName;
|
||
|
$conn->exec($sqlDropUserTable); // drop the table
|
||
|
echo "<p>Deleted!</p><p>Creating new table '" . $userTableName . "'...</p>";
|
||
|
try { // Create the new table
|
||
|
$conn->query($sqlCreateUserTable);
|
||
|
echo "<p>Table '" . $userTableName . "' successfully created (user data)</p>";
|
||
|
} catch (PDOException $e) {
|
||
|
echo $sqlCreateUserTable . "<br>" . $e->getMessage();
|
||
|
}
|
||
|
} else { // If the table doesn't already exist, we'll just create it
|
||
|
try {
|
||
|
$conn->query($sqlCreateUserTable);
|
||
|
echo "<p>Table '" . $userTableName . "' successfully created (user data)</p>";
|
||
|
} catch (PDOException $e) {
|
||
|
echo $sqlCreateUserTable . "<br>" . $e->getMessage();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Check if the users table exists already
|
||
|
$sqlCheckDataTable = $conn->prepare("SHOW TABLES LIKE '" . $dataTableName . "'");
|
||
|
|
||
|
// Run the query
|
||
|
$sqlCheckDataTable->execute();
|
||
|
|
||
|
//Check if any rows exist - if not, create the table, if yes, destroy it first, then create it
|
||
|
$count = $sqlCheckDataTable->rowCount();
|
||
|
|
||
|
if ($count != 0) {
|
||
|
echo "<p>Deleting exsiting table '" . $dataTableName . "'...</p>";
|
||
|
// Create the query to drop the table
|
||
|
$sqlDropDataTable = "DROP TABLE " . $dataTableName;
|
||
|
$conn->exec($sqlDropDataTable); // drop the table
|
||
|
echo "<p>Deleted!</p><p>Creating new table '" . $dataTableName . "'...</p>";
|
||
|
try { // Create the new table
|
||
|
$conn->query($sqlCreateDataTable);
|
||
|
echo "<p>Table '" . $dataTableName . "' successfully created (replay data)</p>";
|
||
|
} catch (PDOException $e) {
|
||
|
echo $sqlCreateDataTable . "<br>" . $e->getMessage();
|
||
|
}
|
||
|
} else { // If the table doesn't already exist, we'll just create it
|
||
|
try {
|
||
|
$conn->query($sqlCreateDataTable);
|
||
|
echo "<p>Table '" . $dataTableName . "' successfully created (replay data)</p>";
|
||
|
} catch (PDOException $e) {
|
||
|
echo $sqlCreateDataTable . "<br>" . $e->getMessage();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$conn = null; // Close the connection
|
||
|
|
||
|
// Tell the use we're done
|
||
|
echo "<p style=\"font-weight:bold\">DONE!</p>";
|
||
|
|
||
|
?>
|
||
|
|
||
|
</body>
|
||
|
|
||
|
</html>
|