php Laravel 5 PDOException 找不到驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35240414/
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
Laravel 5 PDOException Could Not Find Driver
提问by ZZZ
I have a problem using Laravel 5. When I run "php aritsan migrate", I got this error
我在使用 Laravel 5 时遇到问题。当我运行“php aritsan migrate”时,出现此错误
**************************************
* 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?
如何解决?
回答by knalj
Same thing happend to me after upgrading distro.
升级发行版后,同样的事情发生在我身上。
Running sudo apt-get install php7.0-mysql
fixed it for me.
跑步sudo apt-get install php7.0-mysql
为我修好了。
回答by tomsihap
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):
您应该在您的服务器上安装 PDO。编辑您的 php.ini(查看您的phpinfo()
“加载的配置文件”行,以找到 php.ini 文件路径)。查找并取消注释以下行(删除;
字符):
;extension=pdo_mysql.so
Then, restart your Apache server. For more information, please read the documentation.
然后,重新启动 Apache 服务器。有关更多信息,请阅读文档。
回答by Anil Gupta
I'm using Ubuntu 16.04 and PHP 5.6.20
我使用的是 Ubuntu 16.04 和 PHP 5.6.20
After too many problems, the below steps solved this for me:
在太多问题之后,以下步骤为我解决了这个问题:
find
php.ini
path viaphpinfo()
uncomment
extension=php_pdo_mysql.dll
add this line
extension=pdo_mysql.so
then run
sudo apt-get install php-mysql
php.ini
通过查找路径phpinfo()
取消注释
extension=php_pdo_mysql.dll
添加这一行
extension=pdo_mysql.so
然后运行
sudo apt-get install php-mysql
回答by edwinchp
It will depend of your php version. Check it running:
这将取决于您的 php 版本。检查它正在运行:
php -version
Now, according to your current version, run:
现在,根据您当前的版本,运行:
sudo apt-get install php7.2-mysql
回答by Abdul Rehman
I have tried the following command on Ubuntu and its working for me
sudo apt-get install php7.0-mysql
我在 Ubuntu 上尝试了以下命令,它对我有用
sudo apt-get install php7.0-mysql
Thanks
谢谢
回答by Stivenson Mb
If your database is PostgreSQL and you have php7.2 you should run the following commands:
如果你的数据库是 PostgreSQL 并且你有 php7.2 你应该运行以下命令:
sudo apt-get install php7.2-pgsql
and
和
php artisan migrate
回答by Muhammad Sulman
sudo apt-get update
sudo apt-get update
For Mysql Database
对于 Mysql 数据库
sudo apt-get install php-mysql
sudo apt-get install php-mysql
For PostgreSQL Database
对于 PostgreSQL 数据库
sudo apt-get install php-pgsql
sudo apt-get install php-pgsql
Than
比
php artisan migrate
php artisan migrate
回答by daniel
For me the problem was that I was running the migrate command not from inside the container where php was running. The extension was properly set there but not at my host machine.
对我来说,问题是我不是从运行 php 的容器内部运行 migrate 命令。扩展名在那里正确设置,但不在我的主机上。