Iraklis Iraklis - 1 year ago 303
MySQL Question

Cannot connect to Laravel mysql database

I have problems in connected with laravel to mysql database. I have change the localhost to localhost:8091 because this is the local server name in my wamp server. I have also installed xampp and uniserver which listens to other ports. Is it possible that laravel i confused with the other servers i have installed in my machine? Not only for the url but for the phpmyadmin too, for example.

this is the error

PDOException in Connector.php line 119: could not find driver

This is my .env file



This is my config.php file

'mysql' =>
array (
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'test1',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => NULL,

This is my database.php file

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

Solution on last comment of correct answer

Answer Source

You can quickly check if there's a problem with php config. Find your php.ini file, it should be somewhere in xampp folders - do a file search if you have trouble finding it.

Alternatively, you can create a simple file like this:


Or do it the laravel way:

Route::get('info', function() { phpinfo(); });

Now call that route through the browser - you will see php configs.

What you're looking is pdo_mysql. See if it is enabled. If it isn't, go to your php.ini file and find the following line:


Make sure it is uncommented. Restart you servers and you should be good to go.

Also, you do not need to make any changes to database.php or app.php files to connect to the database - changing .env is enough, so remove database connection details from your source files, just leave them as they were initially. Since most of your settings are the same as the defaults, the only parameters that you have to set in .env are:


Try these things and let me know if it helps :)