CodeIgniter Forums
How to set sqlite db path through ROOTPATH variable in .env file - 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: How to set sqlite db path through ROOTPATH variable in .env file (/showthread.php?tid=80053)



How to set sqlite db path through ROOTPATH variable in .env file - dgvirtual - 09-07-2021

If I want to set path to sqlite db in app/config/Database.php file like this:
PHP Code:
'database' => ROOTPATH 'writable/db.sqlite3',
 
'DBDriver' => 'SQLite3'
However, when I tried to do something similar in the .env file, I got error connecting to the database. I was able to connect to db only by using the full system path:
PHP Code:
database.default.database '/home/me/dev/project/writable/db.sqlite3' 
However, this is not the proper way. Is it possible to use ROOTPATH  variable in .env?


RE: How to set sqlite db path through ROOTPATH variable in .env file - paulbalandan - 09-08-2021

Since the .env file is a text file, you cannot use your constants there. You need to write the values themselves (in this case the value of ROOTPATH)


RE: How to set sqlite db path through ROOTPATH variable in .env file - dgvirtual - 09-08-2021

(09-08-2021, 12:25 AM)paulbalandan Wrote: Since the .env file is a text file, you cannot use your constants there. You need to write the values themselves (in this case the value of ROOTPATH)

Agh thank you, that makes sense... and is so unfortunate. Can I perhaps use relative path? No, just checked, neither

Code:
database.default.database = 'writable/db.sqlite3'

nor

Code:
database.default.database = './writable/db.sqlite3'

work...


RE: How to set sqlite db path through ROOTPATH variable in .env file - MGatner - 09-12-2021

You can use relative paths but they are a bit tricky because they are relative to the calling script, which is public/index.php- see https://github.com/codeigniter4projects/playground/blob/develop/.env.example for example:

../writable/database.db


RE: How to set sqlite db path through ROOTPATH variable in .env file - FlavioSuar - 09-13-2021

It would be great to have specific folders for each environment, config, as it was on v3.x..


RE: How to set sqlite db path through ROOTPATH variable in .env file - kilishan - 09-13-2021

(09-13-2021, 03:50 AM)FlavioSuar Wrote: It would be great to have specific folders for each environment, config, as it was on v3.x..

There are some per-environment files at app/Config/Boot where you can customized things. These are called pretty early in the boot cycle but I don't recall exactly how early, so the features already loaded may be hit or miss.


RE: How to set sqlite db path through ROOTPATH variable in .env file - FlavioSuar - 09-14-2021

OK, I'll make some tests...
Big Thank you for CI!!!