Resolving Laravel PDOException: SQLSTATE[HY000] [1049] Unknown Database Error

22 Views Asked by At

I'm new to PHP and Laravel and currently use Windows 10 with XAMPP. I've successfully installed Composer and Laravel, and I'm trying to run my new Laravel project using the URL http://127.0.0.1:8000. However, I'm encountering an error:

SQLSTATE[HY000] [1049] Unknown database 'first-project'

I would appreciate any guidance on how to resolve this issue.

1

There are 1 best solutions below

0
Moisés S. Oliveira On

this error can happen for a number of reasons but one way or another what's happening is that your PHP can't find your database to connect, here's a few suggestions on how you can troubleshoot this issue.

1 - verify the database exists

make sure that you have created your database before trying to reference in your .env file, sometimes we can get ahead of ourselves and end up skipping steps.

2 - verify the name of your database

most likely in your .env file you are giving the wrong reference to the database and that's why you won't be able to connect, check for typos and make sure that the name on your .env is EXACTLY the same name as your database, note that this is case-sensitve.

these are the most common reasons to this type of error but if this doesn't help on your case please share a little more information, specially how you're trying to connect on the .env file of your laravel project.