-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
42 lines (37 loc) · 1.39 KB
/
Copy pathsetup.php
File metadata and controls
42 lines (37 loc) · 1.39 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
41
42
<?php
// Include database configuration
require_once 'config/database.php';
// Create database connection
$database = new Database();
$pdo = $database->getConnection();
try {
// Make sure the student_management database exists
$pdo->exec("CREATE DATABASE IF NOT EXISTS student_management");
echo "Database created or already exists...<br>";
// Create users table
$create_users_table = "CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($create_users_table);
echo "Users table created...<br>";
// Create students table
$create_students_table = "CREATE TABLE IF NOT EXISTS students (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id VARCHAR(50) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_id INT,
FOREIGN KEY (user_id) REFERENCES users(id)
)";
$pdo->exec($create_students_table);
echo "Students table created...<br>";
echo "<br>Setup completed successfully! <a href='index.php'>Go to homepage</a>";
} catch(PDOException $e) {
echo "Error creating database or tables: " . $e->getMessage();
}
?>