Symfony 6 / Doctrine - 驱动程序中发生异常:找不到驱动程序

Bün*_*lin 4 php mysql symfony

我尝试设置我的 symfony 项目,一切都很好,因为我尝试创建学说数据库。我在 .env 文件中写入了 DATABASE_URL,这是正确的,我认为是这样,但是没有任何效果,无论是我的本地 xampp 服务器还是我的 Web 服务器。

我总是得到同样的错误:

[critical] Error thrown while running command "doctrine:database:create". Message: "An exception occurred in the driver: could not find driver"


In ExceptionConverter.php line 119:

  An exception occurred in the driver: could not find driver


In Exception.php line 30:

  could not find driver


In Driver.php line 28:

  could not find driver
Run Code Online (Sandbox Code Playgroud)

小智 8

您可能尚未pdo_mysqlphp.ini文件中启用该扩展名。尝试取消;extension=pdo_mysql注释php.ini.

请注意,您的 php 控制台可能使用php.ini与运行应用程序的文件不同的文件。


小智 5

我也是 Symfony 的初学者,我使用 ubuntu。

我按照以下步骤操作-

  1. 我首先在终端中写入命令:symfony check:requirements了解出了什么问题。
  2. 我得到确认,我pdo_mysql缺少驱动程序,并且由于我使用的是 php 8.2,所以我安装MySQLphp8.2.
  3. 在终端中,键入命令sudo apt-get install -y php8.2-mysql ,然后重新键入命令:php bin/console doctrine:database:create以创建数据库。

让我知道它是否有效。