0

So I have been trying to get an connection my database with homestead, but everytime I make a DB select statement I get an SQLSTATE[HY000] [2002] Connection refused. It seems like my problem is not the same as the others with the same title. I am using homestead with virtual box

Here is my select statement:

   <?php
         echo DB::select('select * from bruger where id = 1')
    ?>;

This is simply to check if I can get any info out.

I have tried various things in both my .env file and and database.php

This is what they are looking like currently:

  'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

and

APP_ENV=local
APP_DEBUG=true
APP_KEY=randomKey
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=phpDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=secret
REDIS_PORT=33060

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
2
  • 'port' => env('DB_PORT', 'localhost'), should be 'port' => env('DB_PORT', '33060'), Commented Jul 1, 2016 at 14:02
  • Already tried that.. Didn't work Commented Jul 1, 2016 at 14:05

2 Answers 2

1

For DB_HOST and DB_PORT try using the IP and port as set in the Homestead.yaml file.

Default:
DB_HOST=192.168.10.10
DB_PORT=3306

Sign up to request clarification or add additional context in comments.

Comments

0

The port should be 3306, since you are accessing from within the homestead machine, if I understood correctly.

In fact, check the documentation

You will use the default 3306 and 5432 ports in your Laravel database configuration file since Laravel is running within the virtual machine.

2 Comments

Okay this gave me an array to string conversion error, but this should managable. Thanks
That's for attempting to echo the result of the DB query. You can try functions print_r or dd instead.

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.