0

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

APP_ENV=local APP_KEY=base64:h0GyUa1VdjV22LXpRiOSOw+9HxXV+Qm0XO2zz9RRz6s= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost:**8091** DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=test1 DB_USERNAME=root DB_PASSWORD= 

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

9
  • stop the local server if youre on something like artisan serve (local php server), do artisan config:clear . serve again and you should be good to go. you also have the password empty (not sure if this is the correct setting or not) Commented Sep 19, 2016 at 12:12
  • Can you post your logs please. Based on your description it's difficult to determine what is going wrong. Commented Sep 19, 2016 at 12:12
  • @SariYono Hey sari, i did what you said and didn;t work and the password should be empty (i think it should be because its suppose to be on wamp). Has the password something to do with artisan serve? I am really new at this so any info would be very useful Commented Sep 19, 2016 at 12:18
  • @AHL its a pdo exception Commented Sep 19, 2016 at 12:19
  • Ok so it looks like there is a problem with your DB connector according to the exception. I can't see what's in your Connector.php on line 119 which is what your exception refers to. But you may check this post (stackoverflow.com/questions/9308147/…) and see if it's a simple configuration problem. I.e. use pdo_mysql as driver instead of mysql. Commented Sep 19, 2016 at 12:25

1 Answer 1

1

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:

<?php phpinfo(); 

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:

extension=php_pdo_mysql.dll 

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:

DB_DATABASE=test1 DB_USERNAME=root 

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

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

6 Comments

Hey Tadas thanks for the reply. In phpinfo i cannot even see pdo_mysql. But in my php ini the line you told is uncommented. In /env i also changed what needed to be change. Nothing works...
I can only see a PDO section where pdo drivers has 'no value'
well here's your problem :). Now we need to figure out how to turn on that PDO driver. It should be as simple as enabling it in php.ini. Notice that comments in ini files begin with semicolon, so make sure that the line in "extension=php_pdo_mysql.dll" in php.ini file has NO semicolon in front of it. Maybe you edited the wrong php.ini file that's left from another instalation or as a backup - do a search for php.ini in files explorer and change that line everywhere. If nothing works, I would encourage you to setup another dev environment, as the one you got is very peculiar.
The problem is that it's ok on my wamp server but not on laravel when i run it with php artisan serve
Find the config file that is used by your local php installation and make the mentioned changes. Artisan serve is most probably not using the same PHP setup as wamp. You have probably set up PHP separately from wamp somewhere in your system. If you're on windows, look into Advanced system settings -> environment variables -> Path variable value - there you will find a path to a PHP setup that is used by artisan.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.