bubble_chart StackLab

Role Based Access Login PHP

5 steps · pending Not started · person_outline Guest
arrow_back Back

Configure the Database Connection

config/config.php The configuration file starts the session, defines database settings, creates the PDO connection, and loads reusable application functions.

code text
session_start();
require_once(__DIR__ . '/../includes/activity-logger.php');

define('BASE_URL', 'http://localhost/it34a');
define('DB_HOST', 'localhost');
define('DB_NAME', 'it34a_lab_db');
define('DB_USER', 'root');
define('DB_PASS', '');

try {
    $pdo = new PDO(
        'mysql:host=' . DB_HOST .
        ';dbname=' . DB_NAME .
        ';charset=utf8mb4',
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES => false
        ]
    );
} catch (PDOException $e) {
    die('Connection failed: ' . $e->getMessage());
}

require_once __DIR__ . '/functions.php';
PDO is ready The $pdo variable can now be used by other application files to communicate with MySQL.

login Sign in to save your progress permanently. info Progress is saved in your browser session
format_list_numbered Step 3 of 5