Skip to content
Advertisement

Laravel not able to connect to database

I am able to connect to have a Laravel app connect to mysql. This is on a a website server not on my local environment if that makes any difference. My issue is I keep getting a error that says

JavaScript

However I am able to connect to mysql if I just have a reguler php file setup with the below

JavaScript

So why does my test php page work but not laravel using the same credentials?

My database.php file looks like this

JavaScript

Advertisement

Answer

It seems like Laravel is using the .env file instead of the values you have assigned in database.php.

Take this line for example:

JavaScript

Laravel will first check if the key DB_DATABASE exists and use the value assigned. If DB_DATABASE does not exist, it will use ‘devcenter’.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement