menu_book Navigation menu

Database Configuration

Pragma CMS uses a multi-tenant architecture. The Platform (Super-Admin) manages its own master database, while each individual site relies on its own dedicated database.

The config_db.php File

To ensure maximum performance and security, database credentials are stored in a site-specific configuration file located at sites/{site_handle}/config_db.php.

This file must return a PHP associative array containing the following keys:

PHP
<?php
// sites/my-site/config_db.php

return [
    'host'     => '127.0.0.1',
    'port'     => '3306',
    'name'     => 'pragma_mysite_db',
    'user'     => 'db_user',
    'password' => 'secure_password'
];

The Connection Lifecycle

Pragma CMS uses a highly secure, static PDO wrapper (Database::class).

When a request targets a specific client site, the index.php router automatically performs a context switch:

  1. It identifies the target site based on the requested domain.
  2. It loads the client's config_db.php.
  3. It forces a reconnection using Database::reconnect(), instantly isolating the request from the Master Platform database.

Security Constraints Enforced Automatically:

  • Prepared Statements Only: The core engine strictly utilizes parameterized queries (PDO::prepare) to prevent SQL Injection.
  • Strict UTF-8: The connection is forced into utf8mb4_unicode_ci at the MySQL server level (PDO::MYSQL_ATTR_INIT_COMMAND), guaranteeing native support for emojis, special characters, and multilingual alphabets.
  • Exception Mode: PDO::ERRMODE_EXCEPTION is globally enabled. Silent database failures are impossible; they are immediately caught and logged.