Multi Database console

I have an application that is sharing code in 100% and the only difference is database each customer is connecting to. In WEB application it was quite easy - I read first part of the hostname (each client gets its own) and I use it to connect to proper db, example: will connect to application_client_name DB

Now I would like to do similar trick in CLI command using Yii - for example to run some maintenance scripts. I know I can do it using curl or something but then some web server limitations apply like timeout for script or something and some of those actions might take some time :wink:

Is it possible to provide to ./yii controller/action a parameter that will be used to create proper connection string or maybe there is a different method you might suggest.

Sure. Console commands do support parameters.

I know, but those are passed to Controller and I need the parameter earlier :wink: Like in config/console.php

I tried adding ./yii test/test --clientName=client_name and in console.php in db config section I added $clientName but it was throwing an error:
PHP Notice: Undefined variable: clientName in /var/www/gekkon/config/console.php on line 6

$db = require(__DIR__ . '/' . $clientName . '_dev_db.php');

Why do you need it earlier? Connection isn’t used before the action itself is started.