Welcome Guest, Not a member yet? Register   Sign In
Support multiple databases for db:table
#1

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);
.... 
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

The option --db seems fine.
Why don't you send a Pull Request?
https://github.com/codeigniter4/CodeIgni...request.md
Reply
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB