CodeIgniter Forums
Unload Database - 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: Unload Database (/showthread.php?tid=80776)



Unload Database - maui82 - 12-16-2021

Hi all, 
I'd like to "unload" Database because I don't need it and, most of all, I don't want to use a local db just to avoid the "db connection error" at the bootstrap. 
I'm using CodeIgniter 4.

Many thanks,
Maui


RE: Unload Database - kenjis - 12-16-2021

Where did you load database?


RE: Unload Database - maui82 - 12-17-2021

(12-16-2021, 09:50 PM)kenjis Wrote: Where did you load database?

it's hard to say because in CI3 I used to load libraries in the autoload.php file: 

Code:
$autoload['libraries'] = array('database', 'session', 'email');


But in CI4 (which I'm using now for the first time) the autoload.php file is slightly different and only contains the following lines (I cut the comments out):

Code:
<?php
namespace Config;
use CodeIgniter\Config\AutoloadConfig;

class Autoload extends AutoloadConfig
{
    public $psr4 = [
        APP_NAMESPACE => APPPATH, [i]// For custom app namespace[/i]
        'Config'      => APPPATH . 'Config',
    ];
    public $classmap = [];
}


I don't know exactly where the database is loaded (but it is, because everything works fine if I define an access in the .env file or in the /app/Config/Database.php)


RE: Unload Database - John_Betong - 12-17-2021

@maui82,

Try setting an incorrect password and see if errors or warnings appear.


RE: Unload Database - iRedds - 12-18-2021

The connection to the database is made on the first request to the database.
Don't want to connect? Do not make inquiries into it.

In CI3, autoloading meant pre-linking libraries. In order not to be distracted by initialization while the application is running.


RE: Unload Database - maui82 - 01-17-2022

(12-18-2021, 05:33 AM)iRedds Wrote: The connection to the database is made on the first request to the database.
Don't want to connect? Do not make inquiries into it.

In CI3, autoloading meant pre-linking libraries. In order not to be distracted by initialization while the application is running.



This helped me solving the problem: the database was loaded in a model.
I removed all the queries and now I don't get any connection error if the db is not reachable.
Thank you very muchs!