【问题标题】:could not find driver in laravel 7 application在 laravel 7 应用程序中找不到驱动程序
【发布时间】:2021-08-26 02:04:44
【问题描述】:

我正在尝试将数据库与我的 Laravel 7 应用程序连接,但每次点击 php artisan migrate 时都会出现以下错误。

我已将我的 .env 文件连接如下:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=""

照亮\数据库\查询异常

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

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +32 vendor frames 
  33  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

我尝试了几种方法,包括取消注释 php.ini 文件中的扩展名,但没有任何改变!

【问题讨论】:

标签: php mysql laravel laravel-7


【解决方案1】:

你在 Linux 上吗?如果是的话,如果你在 Ubuntu 上,你必须安装 php-mysql 包,如果你在 Fedora 上,则必须安装 php-mysqlnd 包。

在 Windows 和 macOS 上,所有这些东西都内置在 WAMP 或 MAMP 或任何其他用途中。

【讨论】:

  • 是的,我正在使用 ubuntu。你能分享安装 php-mysql 的命令吗?非常感谢
  • 当我点击sudo apt-get install php-mysql时,它也显示错误。 The following packages have unmet dependencies: php-mysql : Depends: php7.0-mysql but it is not going to be installed E: Unable to correct problems, you have held broken packages.
  • 您是否从Ondřej Surý 存储库安装了php?我建议您卸载当前安装的 php 并通过执行 sudo apt install php7.4-cli php7.4-json php7.4-xml php7.4-tokenizer php7.4-mysql php7.4-redis php7.4-bcmath php7.4-mbstring 命令重新安装。这包括几乎所有运行 vanilla Laravel 应用程序所需的依赖项。
  • 另外,如果损坏的包问题仍然存在,请尝试link中的解决方案。
  • 非常感谢您的帮助。我已经尝试了所有方法,但仍然无法解决问题。我确定我的 php 或 mysql 有问题。
猜你喜欢
  • 2021-11-14
  • 2018-10-30
  • 2020-09-11
  • 1970-01-01
  • 2020-11-08
  • 1970-01-01
  • 2016-05-16
  • 2019-11-07
相关资源
最近更新 更多