4

I was trying to execute a migrate command in laravel 5. But it shows a PDOException error. I changed database.php file to the following:

  'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'laravel'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'engine'    => null,
        ]
rc0r
  • 18,631
  • 1
  • 16
  • 20
Sujal Patel
  • 592
  • 2
  • 5
  • 14

5 Answers5

7

For PDOException: could not find driver for MySQL, and if it is Debian based OS,

sudo apt-get -y install php5-mysql

For more information read this post PDO Exception

Community
  • 1
  • 1
Md Rashedul Hoque Bhuiyan
  • 10,151
  • 5
  • 30
  • 42
  • already remove comment in php.ini file ==>> extension=php_pdo_mysql.dll , extension=php_pdo_pgsql.dll , extension=php_pdo_sqlite.dll – Sujal Patel Apr 05 '16 at 09:13
5

If you are looking for simple solution, I had same issue & this worked for me..

When you run php artisan from terminal, you invoke php5-cli package.

To run artisan with XAMPP's php you need to use:

/opt/lampp/bin/php artisan migrate

But make sure your /opt/lampp/etc/php.ini is properly configured to enable pdo_mysql

Sujal Patel
  • 592
  • 2
  • 5
  • 14
1

Possible Reason :

  1. Check phpinfo() whether pdo installed or not,if not then enabled from php.ini

Note : PDO driver installed when we install php., php version can also be issue.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
0

You should setup your .env file. If you do not have one, just rename .env.example to .env and use it. Edit it like this:

DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

https://laravel.com/docs/5.2/configuration#environment-configuration

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • i alreay create .env file APP_ENV=local APP_DEBUG=true APP_KEY=sdfdsafdsafsdafasfsfas DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null – Sujal Patel Apr 02 '16 at 06:59
  • So, you still get an error message? If yes, can you show me full error message then? – Alexey Mezenin Apr 02 '16 at 07:01
  • i will use "php artisan migrate" command . it's show [PDOException] could not find driver error msg. – Sujal Patel Apr 02 '16 at 07:05
  • Do you have this line in `database.php`: `'default' => env('DB_CONNECTION', 'mysql'),`? Do you have MySQL installed on your local machine and can you connect to it with MySQL Workbench or similar tool? – Alexey Mezenin Apr 02 '16 at 07:10
  • yes, "'default' => env('DB_CONNECTION', 'mysql')" this line available in database.php file. and yes i have install mysql installed in my local machine. i'm not using any tools like this. – Sujal Patel Apr 02 '16 at 07:16
  • any problem in laravel installation or same alse – Sujal Patel Apr 02 '16 at 07:20
  • I don't think a problem in a Laravel here. It seems you don't have MySQL installed or something. – Alexey Mezenin Apr 02 '16 at 07:23
0

This worked for me "sudo apt-get install php5-sqlite".

Usman
  • 306
  • 1
  • 3