I need to get current and default DB name in cakephp 3.
I know how its possible in cakephp 2 but cannot get a work around for cakephp 3. I have looked into the cakephp library in datasource/connectionManager.php but still i cant get any method to use. Can you please help me out in finding out the current connections config details? Thanks in advance.
I found my answer after looking into some of the core cakephp files. Plus ADmad's answer gave me a hint. I found two ways of doing it.
Method 1: Using Current model Object.
$this->{$modelName}->connection()->config();
will give config, and,
$this->{$modelName}->connection()->config()['database'];
will give the current Database name.
Method 2: Using Datasource Object.
$dataSourceObject = ConnectionManager::get($connectionName); // $connectionName can be 'default'
Config: $dataSourceObject->config();
Current Database name: $dataSourceObject->config()['database'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With