CodeIgniter Forums
Support multiple databases for db:table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Support multiple databases for db:table (/showthread.php?tid=87978)



Support multiple databases for db:table - marekmosna - 07-01-2023

Hi,

I'm mostly working over multiple databases so what I miss is the
Code:
db:table 
command that support multiple connections. It works in application, in migrations but not over
Code:
spark db:table
. I guess it could be just optional argument that determine the configured connection.

I simply did 
PHP Code:
    /**
    * The Command's Usage
    *
    * @var string
    */
    protected $usage = <<<'EOL'
    db:extension [options]

      Examples:
        db:extension --db default
    EOL; 

in custom command to my purposes but it could be system feature.
In case that nodoby (as I supose) wants to fill --db argument the default will be the value as I did in my purpose
PHP Code:
    /**
    * Actually execute a command.
    *
    * @param array $params
    */
    public function run(array $params)
    {
        $dbGroup $params['db'] ?? 'default';

        $db = \Config\Database::connect($dbGroup);
.... 



RE: Support multiple databases for db:table - InsiteFX - 07-02-2023

Connecting to Multiple Databases

If you need to connect to more than one database simultaneously you can do so as follows:

$db1 = \Config\Database::connect('group_one');
$db2 = \Config\Database::connect('group_two');

Note: Change the words group_one and group_two to the specific group names you are connecting to.


RE: Support multiple databases for db:table - kenjis - 10-31-2023

The option --db seems fine.
Why don't you send a Pull Request?
https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md


RE: Support multiple databases for db:table - kenjis - 12-04-2023

I sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/8292