-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateSQL.php
64 lines (53 loc) · 1.41 KB
/
CreateSQL.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
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "ELW";
$table = "lockers";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully\n";
$sql = "CREATE DATABASE ELW";
if (mysqli_query($conn, $sql)) {
echo "Database created successfully\n";
} else {
echo "Error creating database: " . mysqli_error($conn);
}
$sql = "USE ELW";
if (mysqli_query($conn, $sql)) {
echo "Switching to database: ELW\n";
} else {
echo "Error switching database: " . mysqli_error($conn);
}
// sql to create table
$sql = "CREATE TABLE lockers (
locker_number INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(50),
registration_date DateTime,
status enum('reserved','open','out of order','pending'),
renewed boolean,
renewed_date datetime
)";
if (mysqli_query($conn, $sql)) {
echo "Table lockers created successfully\n";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
for($i = 1; $i <= 308; $i++){
$sql = "INSERT INTO lockers (locker_number, status)
VALUES ($i,'open');";
if (mysqli_query($conn, $sql)) {
echo "Initializing locker ";
echo $i."\r";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
echo "\nAll done! \n";
mysqli_close($conn);
?>