Configure::read('Datasources.default') equals null on CakePHP 4.1.1

I can’t read Configure::read(‘Datasources.default’), is resolves to null. I can read, for instance , Configure::read(‘debug’).

When I change the ‘Datasources’ name to ‘Datasources1’ , then Configure::read(‘Datasources1.default’) resolves to a nicely filled array …

When I first do a Configure::load(‘app_local’, ‘default’) then I can Configure::read(‘Datasources.default’).

What is wrong with the ‘Datasources’ name or why is it not loaded?
In bootstrap.php Configure::load(‘app_local’, ‘default’) is loaded.

Hi @hessmac,

You can read database configuration via:

use Cake\Datasource\ConnectionManager;

$connection = ConnectionManager::get('default');

Thanks bizdev, but then I have a connection and I only want to read some of the keys in ‘Datasources.default’. Is that not possilbe?


why Can I read when the name is ‘Datasources1’ …?


You got me reading twice in the book :+1: I now have found that this works for me :


Thank you !

To answer your other question, you can’t read it from the Configuration even though it’s written there, because the creation of the datasource consumes that; it reads and removes it. This is, I assume, for security, so that some malicious bit of code has a much smaller window in which it can access things like your database credentials.


That makes perfect sense, now I understand what was happening .

Thanks a lot for the info!