Reputation: 85
In Laravel 5.3 I am using SQLite
as my default DB
connection and, my .env file I removed all MySQL
connection details. when I use artisan
command and tinker
command to create a new entry and fetch entries are working fine. but from the controller
or eloquent
I cannot fetch or add a record, it throws strange MySQL connection fail error.
PDOException in Connector.php line 55:
SQLSTATE[HY000] [2002] Connection refused
in Connector.php line 55
at PDO->__construct('mysql:host=127.0.0.1;port=3306;dbname=homestead',
'homestead', 'secret', array('0', '2', '0', false, false)) in Connector.php line 55
Upvotes: 1
Views: 2406
Reputation: 2483
If you remove the DB_CONNECTION element in the .env, Laravel will try to use de default configuration, defined in the file config/database.php
The default config is
'default' => env('DB_CONNECTION', 'mysql'),
so you probably are trying to use MySQL
If you want to use SQLite, you should add the next line in the .env file
DB_CONNECTION=sqlite
and adjust the
'database' => env('DB_DATABASE', database_path('database.sqlite')),
in the config/database.php or put your SQLite path in the DB_DATABASE variable, in the .env file.
DB_DATABASE='your SQLite file path'
Upvotes: 3