forked from ShreyashTailor/quiz-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
40 lines (32 loc) · 1.26 KB
/
setup.php
File metadata and controls
40 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include 'db.php';
echo "<h2>Setting up QuizMaster Database Tables...</h2>";
// Read the SQL file
$sql = file_get_contents('database_setup.sql');
// Split the SQL into individual statements
$statements = array_filter(array_map('trim', explode(';', $sql)));
$success_count = 0;
$error_count = 0;
foreach ($statements as $statement) {
if (!empty($statement)) {
if (mysqli_query($conn, $statement)) {
$success_count++;
echo "<p style='color: green;'>✅ Executed successfully: " . substr($statement, 0, 50) . "...</p>";
} else {
$error_count++;
echo "<p style='color: red;'>❌ Error: " . mysqli_error($conn) . "</p>";
echo "<p style='color: red;'>Statement: " . $statement . "</p>";
}
}
}
echo "<h3>Setup Complete!</h3>";
echo "<p>Successfully executed: $success_count statements</p>";
echo "<p>Errors: $error_count</p>";
if ($error_count == 0) {
echo "<p style='color: green; font-weight: bold;'>🎉 Database setup completed successfully!</p>";
echo "<p><a href='index.php'>Go to QuizMaster Home</a></p>";
} else {
echo "<p style='color: red; font-weight: bold;'>⚠️ Some errors occurred during setup. Please check the error messages above.</p>";
}
mysqli_close($conn);
?>