Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoaoHamerski's avatar

How to connect to a sqlite database in runtime execution?

So i have a .sqlite3 file that i get from an API and i store this file in public/cache/, i would like to know how to i connect to this database to perform query search and etc...

0 likes
6 replies
JoaoHamerski's avatar

I already managed to run the database with SQlite DB Browser, but my question is how to load the database in my laravel application and get the data from this database, it is a file .sqlite3 stored in my public/cache/ directory.

mohrad's avatar

modify the db part in .env file with the following

DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite

you may find more info in the documentation here: https://laravel.com/docs/7.x/database

sqlite doesn't require username or password so those shouldn't bother you.

JoaoHamerski's avatar

I was about to try it, thanks, i think it works well, but, how can i change the path to database at runtime? Is it possible?

drewdan's avatar

Why would you wan to change the path at runtime? You could override the config variable, but that would only last for the request you do it on.

JoaoHamerski's avatar

Because the user will choose what database file he want, because there is different language translations to different database files, so, i have to change the database file according to the user choises, this is the way the API i'm working with works.

Please or to participate in this conversation.