I have set up a new Laravel 5.4 project being served by php artisan serve
with a MySQL database all on a Windows machine (I'm not using Homestead or a VM). I am able to run database migrations just fine using php artisan migrate
, but if I try to query the database from a Controller (DB::connection()->select('select * from users');
, for example) I receive the following error:
PDOException in Connector.php line 68: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
I can't figure out why Laravel is unable to query the database. I have tried the following things:
- I can connect to the database through Sqlyog with the same credentials in my
.env
file. - I can run
php artisan migrate:reset
andphp artisan migrate
successfully. - I've tried pointing to both a Microsoft SQL Server running on my local machine as well as a MySQL server running on my local machine. In both cases
php artisan migrate
works fine but I'm not able to run queries through my app. - I've tried switching the
DB_HOST
variable in my.env
file between127.0.0.1
andlocalhost
without luck. - I've tried running
php artisan config:clear
without luck.
Is there a step I'm missing somewhere?