title: CodeIgniter 4 - Multiple Databases Problem with .env file
body: <p>I am using CodeIgniter 4.0.3. I've installed it using <code>composer</code> via:</p>
  
  <p><code>composer create-project codeigniter4/framework</code></p>
  
  <p><em>Got one error after the composer project creation was finished (<code>Script bash admin/setup.sh handling the post-update-cmd event returned with error code 127</code> --- running on Windows 10), but quickly resolved it by editing the <code>composer.json</code> and removing the <code>bash admin/setup.sh</code> directive</em></p>
  
  <p>I've successfully followed up the <a href="https://codeigniter4.github.io/userguide/tutorial/index.html" rel="nofollow noreferrer">tutorial</a> and after that, I decided to make some changes to make it more similar to my web-app requirements, such as adding multiple databases.</p>
  
  <p>Starting with the documentation (<a href="https://codeigniter4.github.io/userguide/database/configuration.html" rel="nofollow noreferrer">here</a> and <a href="https://codeigniter4.github.io/userguide/database/connecting.html" rel="nofollow noreferrer">here</a>), I read that I have to modify my <code>.env</code> file. So, here was the original</p>
  
  <pre><code># ORIGINAL .env
  database.default.hostname = localhost
  database.default.database = ci4
  database.default.username = root
  database.default.password =
  database.default.DBDriver = MySQLi
  </code></pre>
  
  <p>And I wanted to do something like:</p>
  
  <pre><code># MODIFIED .env
  database.primary.hostname = localhost
  database.primary.database = ci4primary
  database.primary.username = root
  database.primary.password =
  database.primary.DBDriver = MySQLi
  
  database.secondary.hostname = localhost
  database.secondary.database = ci4secondary
  database.secondary.username = root
  database.secondary.password =
  database.secondary.DBDriver = MySQLi
  </code></pre>
  
  <p>Next, in my Model I have called Database to connect via:</p>
  
  <pre><code>use Config\Database;
  
  ...
  
  $dbPrimary   = Database::connect('primary');
  $dbSecondary = Database::connect('secondary');
  </code></pre>
  
  <p>When I run the app, I get the following error: </p>
  
  <pre><code>InvalidArgumentException primary is not a valid database connection group
  </code></pre>
  
  <p>I don't know what else to do, I tried various edits of the <code>.env</code> file, tried debugging the <code>Config</code> class (which I think it does not load the <code>primary</code> nor the <code>secondary</code> subkeys --- nor do I have any idea on how to change the class to read them from my environment file).</p>
  
  <p>Quick checklist:</p>
  
  <ul>
  <li><code>env</code> file has been moved to <code>.env</code></li>
  <li>both <code>ci4primary</code> and <code>ci4secondary</code> databases exist and have the proper tables with data</li>
  <li>database credentials are ok</li>
  <li>CI environment is set to development</li>
  </ul>