76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Config;
|
|
|
|
use CodeIgniter\Database\Config;
|
|
|
|
class Database extends Config
|
|
{
|
|
/**
|
|
* Default database group.
|
|
*/
|
|
public string $defaultGroup = 'default';
|
|
|
|
/**
|
|
* Default database connection values
|
|
*/
|
|
public array $default = [
|
|
'DSN' => '',
|
|
'hostname' => '',
|
|
'username' => '',
|
|
'password' => '',
|
|
'database' => '',
|
|
'DBDriver' => 'MySQLi',
|
|
'DBPrefix' => '',
|
|
'pConnect' => false,
|
|
'DBDebug' => true,
|
|
'charset' => 'utf8mb4',
|
|
'DBCollat' => 'utf8mb4_unicode_ci',
|
|
'swapPre' => '',
|
|
'encrypt' => false,
|
|
'compress' => false,
|
|
'strictOn' => false,
|
|
'failover' => [],
|
|
'port' => 3306,
|
|
'numberNative' => false,
|
|
];
|
|
|
|
/**
|
|
* Test database connection values (for PHPUnit)
|
|
*/
|
|
public array $tests = [
|
|
'DSN' => '',
|
|
'hostname' => '127.0.0.1',
|
|
'username' => '',
|
|
'password' => '',
|
|
'database' => ':memory:',
|
|
'DBDriver' => 'SQLite3',
|
|
'DBPrefix' => 'db_',
|
|
'pConnect' => false,
|
|
'DBDebug' => true,
|
|
'charset' => 'utf8',
|
|
'DBCollat' => '',
|
|
'swapPre' => '',
|
|
'encrypt' => false,
|
|
'compress' => false,
|
|
'strictOn' => false,
|
|
'failover' => [],
|
|
'port' => 3306,
|
|
'numberNative' => false,
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Load from environment variables
|
|
$this->default['hostname'] = $_ENV['DB_HOST'] ?? '127.0.0.1';
|
|
$this->default['username'] = $_ENV['DB_USER'] ?? '';
|
|
$this->default['password'] = $_ENV['DB_PASS'] ?? '';
|
|
$this->default['database'] = $_ENV['DB_NAME'] ?? '';
|
|
|
|
// Debug mode based on environment
|
|
$this->default['DBDebug'] = ($_ENV['ENVIRONMENT'] ?? 'development') !== 'production';
|
|
}
|
|
}
|