Database Configuration

SchoolKit is currently designed for MySQL/MariaDB databases. Support for other database systems may be considered in future versions.

Configuration

Configure your database connection in the SchoolKit configuration array. It is highly recommended to use environment variables for credentials to avoid committing them to version control.

<?php
// Example using environment variables
$config = [
    'db' => [
        'dsn' => getenv('DB_DSN'), // e.g., 'mysql:host=localhost;dbname=schoolkit;charset=utf8mb4'
        'user' => getenv('DB_USER'),
        'pass' => getenv('DB_PASS')
    ],
    'storage_path' => __DIR__ . '/storage'
];

$schoolKit = SchoolKit::start($config);
?>

Database Operations

SchoolKit provides a simple, secure database interface built on PDO. See the DB Core Library documentation for a full list of methods.

Retrieving Records

<?php
// Get a single record by ID
$student = $schoolKit->db()->get('students', ['id' => 1]);

// Get multiple records
$activeStudents = $schoolKit->db()->select('students', [
    'grade_level' => '10',
    'status' => 'active'
]);

// Raw query with parameters
$stmt = $schoolKit->db()->query(
    'SELECT * FROM students WHERE grade_level = ? AND status = ?',
    ['10', 'active']
);
$results = $stmt->fetchAll();
?>

Creating Records

<?php
// Insert a new record
$studentId = $schoolKit->db()->insert('students', [
    'first_name' => 'John',
    'last_name' => 'Doe',
    'grade_level' => '10',
    'email' => 'john.doe@school.edu'
]);

echo "Created student with ID: {$studentId}";
?>

Updating Records

<?php
// Update a record
$wasUpdated = $schoolKit->db()->update('students', 
    ['grade_level' => '11'], // Data to update
    ['id' => 1] // Where clause
);

if ($wasUpdated) {
    echo "Student record updated successfully.";
}
?>

Deleting Records

<?php
// Delete a record
$wasDeleted = $schoolKit->db()->delete('students', ['id' => 1]);

if ($wasDeleted) {
    echo "Student record deleted.";
}
?>