简体   繁体   English

无法使用 Symfony 中的 Doctrine 连接到 mysql 数据库

[英]Can't connect to mysql database with Doctrine in Symfony

I'm trying to connect my Symfony 4 application with my mysql database but I'm having some issues.我正在尝试将我的Symfony 4应用程序与我的mysql数据库连接,但我遇到了一些问题。

I have installed doctrine with these commands line: composer require symfony/orm-pack and composer require symfony/maker-bundle --dev .我已经用这些命令行安装了doctrinecomposer require symfony/orm-packcomposer require symfony/maker-bundle --dev After that I have configured the .env to connect to my localhost mysql database with the correct user and password.之后,我将.env配置为使用正确的用户名和密码连接到我的 localhost mysql 数据库。

Then I create my entity class USER and I tried to migrate that entity to the database with the command line php bin/console make:migration but this error appear on my terminal:然后我创建我的entity类 USER 并尝试使用命令行php bin/console make:migration将该entity迁移到数据库,但此错误出现在我的终端上:

In AbstractMySQLDriver.php line 106: An exception occurred in driver: could not find driver在 AbstractMySQLDriver.php 第 106 行:驱动程序中发生异常:找不到驱动程序

In PDOConnection.php line 31: could not find driver在 PDOConnection.php 第 31 行:找不到驱动程序

In PDOConnection.php line 27: could not find driver在 PDOConnection.php 第 27 行:找不到驱动程序

Every step I followed is from the symfony 4 ( https://symfony.com/doc/current/doctrine.html ) documentation.我遵循的每一步都来自symfony 4 ( https://symfony.com/doc/current/doctrine.html ) 文档。 Any idea what am I doing wrong?知道我做错了什么吗?

Thanks.谢谢。

You need to make sure your driver is installed.您需要确保已安装驱动程序。 For Ubuntu 16 and PHP7 use:对于 Ubuntu 16 和 PHP7,请使用:

sudo apt-get install php-mysql

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

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