Welcome Guest, Not a member yet? Register   Sign In
Dynamic Database
#1
Sad 

When i used ci3 i used like this:
Code:
$ci =& get_instance();

and then
Code:
$ci->session->userdata();


to clarify i wold like to load databases dynamically based on my encrypted session.

Rigth now i have : 
Code:
public $default = [
'DSN'      => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => '', // I WOULD LIKE TO CHANGE THIS DYNAMICALLY BUT IN CI4 I DON'T KNOW HOW TO DO. LIKE: $THIS->SESSION->GET('COMPANY');
'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,
];



But now with ci4 i don't know how to do. Anyone can help me? Smile
Reply
#2

(This post was last modified: 02-27-2021, 08:50 AM by motownphilippe.)

I think you can dynamically change the database from your model or other class with
$db->setDatabase($database2_name);

See https://codeigniter.com/user_guide/datab...cting.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB