繁体   English   中英

无法修复 Laravel 迁移中的 PDOException::(“could not find driver”)

[英]Cannot fix PDOException::(“could not find driver”) on Laravel migration

这是我为尝试解决此问题所做的工作列表:

我在 Windows 7 上使用 MAMP。 我的 PHP 版本是 7.3.7。

我得到的完整错误是:

Illuminate\Database\QueryException  : could not find driver (SQL: select * from information_schema.tables where table_schema = lol and table_name = migrations and table_type = 'BASE TABLE')

  at C:\MAMP\htdocs\League Of Legends Backend\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e

    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("could not find driver")
      C:\MAMP\htdocs\League Of Legends Backend\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:31

  2   PDOException::("could not find driver")
      C:\MAMP\htdocs\League Of Legends Backend\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:27

  Please use the argument -v to see more details.

在服务器提供的页面之一上使用phpinfo()以确定 PHP 版本和php.ini文件的位置。 我的 PHP 版本是 7.3.7,我的php.ini文件位于C:\\MAMP\\conf\\php7.3.7\\php.ini 这 3 行在该文件中未注释:

extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll

在服务器提供的页面之一上使用 get_loaded_extensions 以查看所有加载的扩展。 这是清单:

array:45 [▼
  0 => "Core"
  1 => "bcmath"
  2 => "calendar"
  3 => "com_dotnet"
  4 => "ctype"
  5 => "date"
  6 => "filter"
  7 => "hash"
  8 => "iconv"
  9 => "json"
  10 => "SPL"
  11 => "odbc"
  12 => "pcre"
  13 => "Reflection"
  14 => "session"
  15 => "sockets"
  16 => "standard"
  17 => "mysqlnd"
  18 => "tokenizer"
  19 => "zip"
  20 => "zlib"
  21 => "libxml"
  22 => "dom"
  23 => "PDO"
  24 => "bz2"
  25 => "SimpleXML"
  26 => "soap"
  27 => "xml"
  28 => "wddx"
  29 => "xmlreader"
  30 => "xmlwriter"
  31 => "apache2handler"
  32 => "openssl"
  33 => "gd"
  34 => "gettext"
  35 => "mbstring"
  36 => "exif"
  37 => "mysqli"
  38 => "pdo_sqlite"
  39 => "sqlite3"
  40 => "curl"
  41 => "Phar"
  42 => "imagick"
  43 => "pdo_mysql"
  44 => "fileinfo"
]

在 Laravel 的 database.php 文件中,MySQL 被设置为默认值:

'default' => env('DB_CONNECTION', 'mysql'),

我也尝试使用 composer update 和 composer dump-autoload 。

我的数据库环境变量设置正确。 我可以通过插入、删除、更新和选择与我的数据库进行交互,但是,由于某种原因我无法迁移:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lol
DB_USERNAME=root
DB_PASSWORD=root

我已经在这里阅读了所有类似的问题,现在我别无选择。

您需要为 php 安装驱动程序 mysql。 ubuntu sudo apt install php-mysql示例

您可以尝试在包含内容的公共文件夹下添加一个名为 php.php 的文件吗

<?php phpinfo ?>

并通过 Web URL 而不是命令行访问它,并确保启用了 mysql pdo 扩展

这意味着对于命令行可能使用了您更新的其他php.ini 这就是为什么在运行站点时一切正常,而从控制台运行 PHP 时却没有的原因。

你应该跑

php --ini

在命令行中查看使用了哪些配置文件,并确保您已在其中启用 MySQL。

您需要检查是否有 mysql pdo 扩展,还需要检查系统上运行的 DATABASE_TABLE 是否存在,否则您必须安装它。 当您尝试使用不在您机器上的数据库时会显示该错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM