簡體   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