Is it possible to change only database name of default group in Codeigniter 4?

Viewed 13

I have multiple databases. Depending on user logged in I want to connect that user to database which is specified in database table.

I have tried below code, where database name will come from database table

$custom = [
            'DSN'      => '',
            'hostname' => 'localhost',
            'username' => '',
            'password' => '',
            'database' => '',
            'DBDriver' => 'MySQLi',
            'DBPrefix' => '',
            'pConnect' => false,
            'DBDebug'  => (ENVIRONMENT !== 'production'),
            'cacheOn'  => false,
            'cacheDir' => '',
            'charset'  => 'utf8',
            'DBCollat' => 'utf8_general_ci',
            'swapPre'  => '',
            'encrypt'  => false,
            'compress' => false,
            'strictOn' => false,
            'failover' => [],
            'port'     => 3306,
    ];
$db = \Config\Database::connect($custom);

But when i try to access this $db object in model it not accesible in model

0 Answers
Related