Switch Database |
Documentation on Working With Databases provides with 2 straight forward ways:
In more detail: Option 1: Add connections by copy, pasting and renaming 'public $default' to e.g. 'public $my_db_1', 'public $my_db_2', and when want to choose which one to use, just load the DB config you added with: PHP Code: $db_1 = \Config\Database::connect('my_db_1'); Option 2: Similar initiation, just instead passing an array which you can change while running your model: PHP Code: $custom = [ EDIT: Just realised that you posted under CI3. Your requirement is supported out of the box even in CI3, described here in "Connecting to your Database". There's all the flexibility you need. The logic is the same. I will leave CI4 version as is. |
Messages In This Thread |
Switch Database - by federcla - 04-13-2020, 10:44 AM
RE: Switch Database - by cyberstunts - 04-13-2020, 05:04 PM
RE: Switch Database - by federcla - 04-14-2020, 03:43 AM
RE: Switch Database - by cyberstunts - 04-14-2020, 05:41 AM
|