Welcome Guest, Not a member yet? Register   Sign In
How to set sqlite db path through ROOTPATH variable in .env file
#1

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?
==

Donatas G.
Reply
#2

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)
Reply
#3

(This post was last modified: 09-08-2021, 12:37 AM by dgvirtual.)

(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...
==

Donatas G.
Reply
#4

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/...nv.example for example:

../writable/database.db
Reply
#5

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

(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.
Reply
#7

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




Theme © iAndrew 2016 - Forum software by © MyBB