使用 XAMPP 的 Laravel 迁移错误:[PDOException] 找不到驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27361413/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:32:23  来源:igfitidea点击:

Laravel migration error using XAMPP: [PDOException] could not find driver

phplaravel

提问by cchapman

I've seen a few similar questions to this one, but they seemed to be primarily addressing different environments than what I am using, so I hope this isn't a repeat.

我见过一些与此类似的问题,但它们似乎主要解决与我使用的环境不同的环境,所以我希望这不是重复。

I am trying to do a test migration in Laravel 4.2 on my local server using XAMPP on Windows 7. When I try to run php artisan migrate, I get the error:

我正在尝试使用 Windows 7 上的 XAMPP 在本地服务器上的 Laravel 4.2 中进行测试迁移。当我尝试运行时php artisan migrate,出现错误:

  [PDOException]
  could not find driver



migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--pac
kage[="..."]] [--pretend] [--seed]

Most other suggestions I've seen are in regards to the php.ini file, but I do have the necessary line uncommented:

我见过的大多数其他建议都与 php.ini 文件有关,但我确实没有注释掉必要的行:

extension=php_pdo_mysql.dll

And it appears to be running when I view my phpinfo():

当我查看我的 phpinfo() 时,它似乎正在运行:

                 mysqlnd
...
API Extensions          mysql,mysqli,pdo_mysql


                 pdo_mysql
PDO Driver for MySQL    enabled
Client API version      mysqlnd 5.0.11-dev - 20120503 - $Id: 
                        bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $

My only thought is that it might be an issue with my running XAMPP on ports 81 and 3307 instead of the default 80 and 3306 (although I believe I do have XAMPP's config files correctly configured, since I've been able to run other applications fine on these ports). Are there any other Laravel config files I might have missed though?

我唯一的想法是我在端口 81 和 3307 而不是默认的 80 和 3306 上运行 XAMPP 可能有问题(尽管我相信我确实正确配置了 XAMPP 的配置文件,因为我已经能够正常运行其他应用程序在这些端口上)。有没有我可能错过的其他 Laravel 配置文件?

Edit 11/15I see that there was a similar question asked here, but for what it's worth it appears that that error for that user had occurred afterthe installation process (it appeared to have been resolved through Laravel instead of through the php.ini file). This specific problem appears to have been related to the installation process itself, and appears to have help at least a few people that also were unable to find the specific answer in other versions of the question.

编辑11/15我看到有一个类似的问题问在这里,但它的价值似乎已发生的错误该用户之后安装过程(它似乎已通过Laravel而不是通过php.ini中解决文件)。这个特定问题似乎与安装过程本身有关,并且似乎对至少一些在其他版本的问题中也无法找到具体答案的人有所帮助。

采纳答案by Yousof K.

This can happen for a Number of reasons. Either the Default DB type is not set (config/database.php), or the Extension is not enabled, or you HAVE enabled the extension but have NOT restarted XAMPP, or the PATH settings under environment settings are not properly defined.

发生这种情况的原因有很多。要么未设置默认 DB 类型(config/database.php),要么未启用扩展,要么已启用扩展但尚未重新启动 XAMPP,或未正确定义环境设置下的 PATH 设置。

I suggest you check out this answer which may solve the issue: https://stackoverflow.com/a/25336292/2745485

我建议您查看这个可能解决问题的答案:https: //stackoverflow.com/a/25336292/2745485

Regards.

问候。

回答by cchapman

So it did turn out to be a problem with the PATH settings. Thank you very much @ykbks. The link provided wasn't quite clear on how to diagnose it though, so just to expand on that in hopes it helps someone in the same position, from the command line I ran

所以结果证明是 PATH 设置的问题。非常感谢@ykbks。提供的链接虽然不太清楚如何诊断它,所以只是扩展它,希望它可以帮助处于相同位置的人,从我运行的命令行

C:\>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         (none)        <<Problem
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

So I kept changing the php.ini file that wasn't being seen by the system. I added XAMPP's php folder to the PATH and the migrate ran perfectly.

所以我一直在修改系统看不到的 php.ini 文件。我将 XAMPP 的 php 文件夹添加到 PATH 并且迁移运行完美。

回答by Todor Todorov

I had this error using Laravel 5.1 on Linux Ubuntu 15.10 with php5-fpmand NGINX. Seems like the problem comes due to missing PHP module. I resolved this installing on my system php5-mysql. Simply run:

我在 Linux Ubuntu 15.10php5-fpm和 NGINX上使用 Laravel 5.1 时遇到了这个错误。问题似乎是由于缺少 PHP 模块造成的。我在我的系统上解决了这个安装问题php5-mysql。只需运行:

sudo apt-get install php5-mysql

On Windows this can be fixed I hope including the MySQL module in php.inifile. On XAMPP this should be included by default.

在 Windows 上,这可以修复我希望在php.ini文件中包含 MySQL 模块。在 XAMPP 上,这应该默认包含在内。