CodeIgniter Forums
Database session - No database selected - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Database session - No database selected (/showthread.php?tid=71967)



Database session - No database selected - happyape - 10-19-2018

I was going to ask this question but fortunately found the answer by digging into the session handler file.

The main issue is that the documentation doesn't mention yet about this property in the App.php

Code:
public $sessionDBGroup

As in my case, in the config/Database.php - I have two groups "development" and "production" i.e. no "default" group because I had set $defaultGroup = ENVIRONMENT; . This created issue for me as \CodeIgniter\Session\Handlers\DatabaseHandler file was looking for database name in the "default" group.

Code:
$this->DBGroup = ! empty($config->sessionDBGroup) ? $config->sessionDBGroup : 'default';

If you happen to have the same issue, then all you need to do is that in you App.php just add public $sessionDBGroup = ENVIRONMENT; or name of whatever database group you are using.

Hope that helps anyone having similar issue.