0
votes

How can I connect to Sqlite db?

I have done the below things

1) Created project.
2) Created database.sqlite inside the database folder (database\database.sqlite).
3) Changed 'default' => env ('DB_CONNECTION', 'mysql'), to 'default' => env ('DB_CONNECTION', 'sqlite'), in the database.php file.
4) Ran php artisan migrate.

But I am getting an error

[InvalidArgumentException]
Database (sqlite) does not exist.

Then I tried DB_DATABASE=database\database.sqlite as stated in the documentation but I get the following error.

[PDOException]
Could not find driver

I have set the .env file as below

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret
1
do you define your DB_USERNAME and DB_PASSWORD?farhad goodarzi
i mean, can you go to your sqlite by username:homestead and password:secretfarhad goodarzi
Yes, I have defined DB_USERNAME and DB_PASSWORDVijayanand Premnath
Yes I can go to sqlite using username:homestead and password:secretVijayanand Premnath
do you configure the 'default' key in app/config/database.php?farhad goodarzi

1 Answers

0
votes

Sqlite is available for the CLI, but not for PHP. You need to install it. Run the below command in terminal

$ sudo apt-get install php5-sqlite

If you're running php7, you need to install php7.0-sqlite. After that restart your apache or whatever web server you have.