Laravel 5 PDOException Could Not Find Driver

2019-01-07 23:02发布

I have a problem using Laravel 5. When I run "php aritsan migrate", I got this error

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? [y/N] y

[PDOException]
could not find driver

I could run the application, but when database connection needed, I got this error

PDOException in Connector.php line 55:
could not find driver
in Connector.php line 55
at PDO->__construct('mysql:host=localhost;dbname=mydb', 'root', '', array('0', '2', '0', false, false)) in Connector.php line 55
at Connector->createConnection('mysql:host=localhost;dbname=mydb', array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'mydb', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 22

How to fix it?

5条回答
smile是对你的礼貌
2楼-- · 2019-01-07 23:08

Same thing happend to me after upgrading distro.

Running sudo apt-get install php7.0-mysql fixed it for me.

查看更多
叛逆
3楼-- · 2019-01-07 23:15

It will depend of your php version. Check it running:

php -version

Now, according to your current version, run:

sudo apt-get install php7.2-mysql
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-07 23:21

I'm using Ubuntu 16.04 and PHP 5.6.20

After too many problems, the below steps solved this for me:

  1. find php.ini path via phpinfo()

  2. uncomment

    extension=php_pdo_mysql.dll
    
  3. add this line

    extension=pdo_mysql.so
    
  4. then run

    sudo apt-get install php-mysql
    
查看更多
Evening l夕情丶
5楼-- · 2019-01-07 23:24

You should install PDO on your server. Edit your php.ini (look at your phpinfo(), "Loaded Configuration File" line, to find the php.ini file path). Find and uncomment the following line (remove the ; character):

;extension=pdo_mysql.so

Then, restart your Apache server. For more information, please read the documentation.

查看更多
对你真心纯属浪费
6楼-- · 2019-01-07 23:31

I have tried the following command on Ubuntu and its working for me sudo apt-get install php7.0-mysql

Thanks

查看更多
登录 后发表回答