forked from BryanTheLai/RestaurantProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
40 lines (34 loc) · 1.6 KB
/
index.php
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
// Check if setup has already been completed
if (file_exists('setup_completed.flag')) {
echo "Setup has already been completed. The SQL setup won't run again.If not created,open this project in the file explorer and delete setup_completed.flag.It should be next to the index.php file.";
} else {
require_once 'customerSide/config.php';
// Create the 'restaurantdb' database if it doesn't exist
$sqlCreateDB = "CREATE DATABASE IF NOT EXISTS restaurantdb"; // Change 'restaurantdb' to your actual database name
if ($link->query($sqlCreateDB) === TRUE) {
echo "Database 'restaurantdb' created successfully.<br>";
} else {
echo "Error creating database: " . $link->error . "<br>";
}
// Switch to using the 'restaurantdb' database
$link->select_db('restaurantdb'); // Change 'restaurantdb' to your actual database name
// Execute SQL statements from "restaurantdb.txt"
function executeSQLFromFile($filename, $link) {
$sql = file_get_contents($filename);
// Execute the SQL statements
if ($link->multi_query($sql) === TRUE) {
echo "SQL statements executed successfully.";
// Set the flag to indicate setup is complete
file_put_contents('setup_completed.flag', 'Setup completed successfully.');
} else {
echo "Error executing SQL statements: " . $link->error;
}
}
// Execute SQL statements from "restaurantdb.txt"
executeSQLFromFile('restaurantdb.txt', $link);
// Close the database connection
$link->close();
}
?>
<a href="customerSide/home/home.php">Home</a>