php artisan migrate 抛出 [PDO Exception] 找不到驱动程序 - 使用 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22463614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php artisan migrate throwing [PDO Exception] Could not find driver - Using Laravel
提问by Vamshi Vangapally
I have a bad experience while installing laravel. However, I was able to do so and move to the next level. I used generators and created my migrations. But when I type the last command
我在安装 Laravel 时遇到了糟糕的经历。但是,我能够这样做并进入下一个级别。我使用了生成器并创建了我的迁移。但是当我输入最后一个命令时
php artisan migrate
It's throwing a PDOException - could not find driver.
它抛出一个 PDOException - 找不到驱动程序。
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
That's my configuration in config/database.php.
这是我在 config/database.php 中的配置。
I tried searching on stackoverflow and laravel forums and people suggest that it's PDO problem and not artisan's or php's - I followed those suggestions like adding
我尝试在 stackoverflow 和 laravel 论坛上搜索,人们建议这是 PDO 问题,而不是工匠或 php 的问题-我遵循了这些建议,例如添加
extension=pgsql.so
extension=pdo_pgsql.so
in php.ini
在 php.ini
No positive result. It always says [PDOException]could not find driver.
没有阳性结果。它总是说[PDOException]could not find driver.
Can someone please help resolving this.
有人可以帮助解决这个问题。
Environment that I am using: Mac, laravel 4, MAMP PRO with php 5.4.4
我使用的环境:Mac、laravel 4、MAMP PRO with php 5.4.4
回答by narendro
You can use
您可以使用
sudo apt-get install php7-mysql
or
或者
sudo apt-get install php5-mysql
or
或者
sudo apt-get install php-mysql
This worked for me.
这对我有用。
回答by Alejandro
This worked for me:
这对我有用:
sudo apt-get install php5-sqlite
This installed sqlite for php5, then I ran the php artisan migrate command again and worked perfectly.
这为 php5 安装了 sqlite,然后我再次运行 php artisan migrate 命令并完美运行。
回答by JaTochNietDan
You need to specifically enable the pdo_mysql plugin. Assuming you're using a standard PHP installation, then generally you would simply need to add this to your PHP.ini file:
您需要专门启用 pdo_mysql 插件。假设您使用的是标准 PHP 安装,那么通常您只需将其添加到您的 PHP.ini 文件中:
extension=pdo_mysql.so
You need to ensure that this file exists in the extension directory though.
不过,您需要确保此文件存在于扩展目录中。
Adding pdo_pgsql.sodoesn't help because that is for PostgreSQL.
添加pdo_pgsql.so无济于事,因为那是针对 PostgreSQL 的。
Additionally, you should ensure that you restart the web-server after you make the changes to the PHP ini file, as the changes may not be reflected otherwise.
此外,您应该确保在对 PHP ini 文件进行更改后重新启动 Web 服务器,否则更改可能不会反映出来。
回答by Leith
Ran into the same issue here, and turns out this is because PHP at the command line uses a different php.inifile from the browser version, which is why it looks like it's loading the extension correctly when you look at phpinfo()in a browser.
在这里遇到了同样的问题,结果证明这是因为命令行中的 PHP 使用了php.ini与浏览器版本不同的文件,这就是为什么当您phpinfo()在浏览器中查看时,它看起来像是正确加载了扩展程序。
As per this answer, you just need to run:
根据这个答案,您只需要运行:
php --ini
At the command line, which will tell you the path to the currently loaded php.ini(probably actually a php-cli.inifile located in the same place as your regular php.inifile).
在命令行中,它会告诉您当前加载的路径php.ini(可能实际上是一个php-cli.ini与常规php.ini文件位于同一位置的文件)。
Once you've found that, modify it with the pdo extensions you want (in this case for MySQL):
找到后,使用所需的 pdo 扩展名修改它(在本例中为 MySQL):
extension=pdo_mysql.so
Or, for any other users that are on Windows using some kind of WAMP server, it probably looks like this instead:
或者,对于使用某种 WAMP 服务器的 Windows 上的任何其他用户,它可能看起来像这样:
extension=php_pdo_mysql.dll
回答by Robin Wang
I think you missed the mysql driver for php5. Execute below command:
我想你错过了 php5 的 mysql 驱动程序。执行以下命令:
sudo apt-get install php5-mysql
/etc/init.d/php5-fpm restart
回答by abhishek subedi
You are missing a PDO driver.
您缺少 PDO 驱动程序。
First install the driver
首先安装驱动
For ubuntu: For mysql database.
对于 ubuntu:对于 mysql 数据库。
sudo apt-get install php5.6-mysql/php7.2-mysql
须藤 apt-get 安装 php5.6-mysql/php7.2-mysql
You also can search for other database systems.
您还可以搜索其他数据库系统。
You also can search for the driver:
您也可以搜索驱动程序:
sudo apt-cache search drivername
sudo apt-cache 搜索驱动程序名称
Then Run the cmd php artisan migrate
回答by Thach Van
Please check your Laravel .envfile also. Make sure DB_CONNECTION=mysql, otherwise it won't work with MySQL. It tried to load something else.
请同时检查您的 Laravel.env文件。确保DB_CONNECTION=mysql,否则它将无法与 MySQL 一起使用。它试图加载其他东西。
回答by hmmm
I was also getting the same error --> "[PDOException]
could not find driver "
我也遇到了同样的错误 -->“[PDOException]
找不到驱动程序”
After that I used many commands but not didn't get any help
之后我使用了很多命令但没有得到任何帮助
Finally I used the following command, which solved my problem.
最后我使用了以下命令,解决了我的问题。
sudo apt-get install php5-sqlite
须藤 apt-get 安装 php5-sqlite
回答by JalalKun
You must be installing the latest version of php mysqlin my case I am install php7.1-mysql
php mysql在我的情况下,您必须安装最新版本,我正在安装php7.1-mysql
Try this
尝试这个
sudo apt-get install php7.1-mysql
I am using the latest version of laravel
我正在使用最新版本的 Laravel
回答by Sagar Koshti
Laravel Testingwith sqliteneeds php pdo sqlite drivers
使用sqlite 进行Laravel 测试需要 php pdo sqlite 驱动程序
For Ubuntu 14.04
对于 Ubuntu 14.04
sudo apt-get install php5-sqlite
sudo service apache2 restart
In ubuntu 16.04 there is no php5-sqlite
在 ubuntu 16.04 中没有 php5-sqlite
sudo apt-get install php7.0-sqlite
sudo service apache2 restart

