-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.php
51 lines (42 loc) · 1.61 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
41
42
43
44
45
46
47
48
49
50
51
<?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.";
} else {
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
// Create Connection
$link = new mysqli(DB_HOST, DB_USER, DB_PASS);
// Check Connection
if ($link->connect_error) {
die('Connection Failed: ' . $link->connect_error);
}
// Create the 'restaurantdb' database if it doesn't exist
$sqlCreateDB = "CREATE DATABASE IF NOT EXISTS restaurantdb";
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');
// 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>