Overview
The QR Attendance System uses a MySQL database namedqr_attendance with 7 interconnected tables that manage users, classes, schedules, and attendance records.
Entity Relationship Overview
The database schema follows a relational structure with the following key relationships:- Teachers create and manage Classes
- Students can be enrolled in multiple Classes through Class Students (many-to-many)
- Classes have scheduled meeting times via Class Schedules
- Attendance records track student presence in specific classes
- Admins have system-wide administrative privileges
Tables
Students Table
students
students
Stores student account information and QR codes for attendance scanning.
Fields
Primary key, auto-incrementing unique identifier
Unique student identifier (e.g., student number or ID card number)
Full name of the student
Unique email address for login and communication
Hashed password for authentication
Encoded QR code data for attendance scanning
Token for password reset functionality (nullable)
Expiration timestamp for the reset token (nullable)
Constraints
- Primary Key:
id - Unique Keys:
student_id,email - Indexes: Automatic indexes on unique fields
Teachers Table
teachers
teachers
Stores teacher account information and credentials.
Fields
Primary key, auto-incrementing unique identifier
Unique teacher identifier used for referencing in classes
Full name of the teacher
Email address for login and communication
Hashed password for authentication
Token for password reset functionality (nullable)
Expiration timestamp for the reset token (nullable)
Constraints
- Primary Key:
id - Unique Key:
teacher_id - Referenced By:
classes.teacher_id
Admins Table
admins
admins
Stores administrator credentials for system management.
Fields
Primary key, auto-incrementing unique identifier
Unique username for admin login
Hashed password for authentication
Constraints
- Primary Key:
id - Unique Key:
username
Default Data
The system automatically creates a default admin account:- Username:
admin - Password:
admin123(hashed)
Classes Table
classes
classes
Stores class/course information managed by teachers.
Fields
Primary key, auto-incrementing unique identifier
Reference to the teacher who manages this class
Name or title of the class/course
Constraints
- Primary Key:
id - Foreign Key:
teacher_idreferencesteachers(teacher_id) - Referenced By:
class_students.class_id,class_schedules.class_id,attendance.class_id
Class Students Table
class_students
class_students
Junction table managing the many-to-many relationship between students and classes.
Fields
Primary key, auto-incrementing unique identifier
Reference to the class
Reference to the enrolled student
Constraints
- Primary Key:
id - Foreign Keys:
class_idreferencesclasses(id)student_idreferencesstudents(student_id)
Class Schedules Table
class_schedules
class_schedules
Defines the weekly schedule for each class, including meeting times and grace periods.
Fields
Primary key, auto-incrementing unique identifier
Reference to the class being scheduled
Day of the week (typically 0-6 or 1-7, depending on implementation)
Start time of the class session
Grace period in minutes for late arrivals (default: 15 minutes)
Constraints
- Primary Key:
id - Unique Key:
unique_class_dayon (class_id,day_of_week) - prevents duplicate schedules for the same class on the same day - Foreign Key:
class_idreferencesclasses(id)
Attendance Table
attendance
attendance
Records student attendance for specific classes on specific dates.
Fields
Primary key, auto-incrementing unique identifier
Reference to the student being marked
Reference to the class session
Date of the attendance record
Time when attendance was recorded
Attendance status (e.g., ‘present’, ‘absent’, ‘late’)
Constraints
- Primary Key:
id - Foreign Keys:
student_idreferencesstudents(student_id)class_idreferencesclasses(id)
Database Relationships
One-to-Many Relationships
| Parent Table | Child Table | Relationship |
|---|---|---|
teachers | classes | One teacher can manage multiple classes |
classes | class_students | One class can have multiple student enrollments |
classes | class_schedules | One class can have multiple scheduled sessions |
classes | attendance | One class can have multiple attendance records |
students | class_students | One student can enroll in multiple classes |
students | attendance | One student can have multiple attendance records |
Many-to-Many Relationships
| Table 1 | Junction Table | Table 2 | Description |
|---|---|---|---|
students | class_students | classes | Students can enroll in multiple classes; classes can have multiple students |
Connection Configuration
The database connection is configured inconfig.php:
Initialization
All tables are created automatically whenconfig.php is first loaded. The schema includes:
- Auto-increment primary keys on all tables
- Foreign key constraints for referential integrity
- Unique constraints to prevent duplicate entries
- Default values for optional fields
- Automatic creation of a default admin account
Password reset functionality is supported for both students and teachers through the
reset_token and reset_token_expiry columns.