Overview
The QR Attendance System uses MySQL as its database backend with PDO for secure database interactions. All database configuration and table initialization happens inconfig.php.
Database Configuration
Connection Settings
The database connection is configured inconfig.php:3-10 with the following parameters:
config.php
The PDO connection uses
PDO::ERRMODE_EXCEPTION to throw exceptions on errors, enabling proper error handling throughout the application.Setup Steps
Database Schema
All tables are created automatically whenconfig.php is loaded. Below are the complete schemas:
Students Table
Stores student account information and QR codes.config.php:13-24
student_id: Unique student identifier (e.g., numeric ID)qr_code: Stores QR code data for attendance scanningreset_token: Temporary token for password reset functionalityreset_token_expiry: Token expiration timestamp
Teachers Table
Stores teacher account information.config.php:34-44
teacher_id: Unique teacher identifier (format: T followed by 4 digits, e.g., T1234)reset_tokenandreset_token_expiry: Used for password reset flow
Admins Table
Stores administrator credentials.config.php:27-31
Classes Table
Defines classes taught by teachers.config.php:46-52
Class Students Table
Maps students to their enrolled classes (many-to-many relationship).config.php:54-61
Class Schedules Table
Defines when classes meet during the week.config.php:63-72
day_of_week: Integer representing day (0 = Sunday, 6 = Saturday)grace_period: Minutes after start_time that students can still mark attendance
Attendance Table
Records student attendance for each class session.config.php:74-84
present: Student attended on timelate: Student attended after grace periodabsent: Student did not attend (default)
Default Data
The system automatically creates a default administrator account:config.php:86-92
- Username:
admin - Password:
admin123
PDO Configuration
The system uses PHP Data Objects (PDO) for all database operations:config.php:9-10
- Prepared statements prevent SQL injection
- Exception-based error handling
- Database-agnostic code (portable to other databases)
- Better performance with statement reuse
Troubleshooting
Connection Fails
If you see “Connection failed” errors:- Verify MySQL is running
- Check database credentials in
config.php - Ensure the
qr_attendancedatabase exists - Verify user has proper permissions
Table Creation Errors
If tables aren’t created:- Check MySQL user has CREATE TABLE privileges
- Review error messages in browser or logs
- Manually create tables using the SQL schemas above
Foreign Key Constraints
If you encounter foreign key errors:- Ensure InnoDB engine is used (default for MySQL 5.5+)
- Create tables in order: teachers → classes → class_schedules, students → class_students
- Verify referenced columns exist and have correct data types