1

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
2
  • is your mysql up and running? Commented Jul 30, 2016 at 10:18
  • no, but I'm using sqlite Commented Jul 30, 2016 at 10:19

1 Answer 1

3

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.