Início / Optitravel / Core / Database
Use DB Class
Get Central DB (Optitravel)
To get the Central DB we should use the class App\Core\Database\DB with the function getCentral().
use App\Core\Database\DB;
$centralDb = DB::getCentral();
Get System DB
To get the System DB we have to take into consideration the existance of the System ID variable ($_SESSION['kt_system_id']).
If the variable is set, we can simply call it like this:
use App\Core\Database\DB;
$systemDb = DB::getSystem();
If the variable is not set (Ex: crons), it needs to be passed as a string argument:
use App\Core\Database\DB;
// Recommended way with the ID
$systemDb = DB::getSystem('26');
// Alternate version with the System Code
$systemDb = DB::getSystem('DEMO');
Get Logs DB
For the Logs DB, it can be the System DB (default) or can use an external DB. This is set in the .env.php:
# DB - Logs
DB_LOGS_EXTERNAL='0'
DB_LOGS_HOST=''
DB_LOGS_PORT=''
DB_LOGS_DB=''
DB_LOGS_USERNAME=''
DB_LOGS_PASSWORD=''
If DB_LOGS_EXTERNAL is set with 0, it uses the System DB. If is set with 1, it uses the configuration set in the following settings.
Like the System DB, the System ID could be passed based in the existance of $_SESSION['kt_system_id'].
If the variable is set, we can simply call it like this:
use App\Core\Database\DB;
$logsDb = DB::getLogs();
If the variable is not set (Ex: crons), it needs to be passed as a string argument:
use App\Core\Database\DB;
// Recommended way with the ID
$logsDb = DB::getLogs('26');
// Alternate version with the System Code
$logsDb = DB::getLogs('DEMO');
↑ (Última atualização: 18/06/2025)