Symfony 5 - “驱动程序中发生异常:找不到驱动程序”

Thi*_*rry 12 sql symfony

我目前面临这个问题。我真的是 Symfony 的新手。

问题:当我使用 cli 创建新数据库时symfony console doctrine:database:create,出现以下错误:

In AbstractPostgreSQLDriver.php line 102:

  An exception occurred in driver: could not find driver  


In Exception.php line 18:

  could not find driver  


In PDOConnection.php line 38:

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

我使用 php 7.4 和 xampp 并正常安装 pdo_sql :

extension=bz2
extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop
Run Code Online (Sandbox Code Playgroud)

这是我的 .env 文件配置:

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://root:@127.0.0.1:3306/dbname"
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###
Run Code Online (Sandbox Code Playgroud)

这是我的doctrine.yaml 文件配置:

doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'
    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    #server_version: '13'
orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App
Run Code Online (Sandbox Code Playgroud)

我已经搜索了几个小时,但找不到任何解决方案来解决我的问题,有人有想法吗?我在窗户上。

多谢 !

dıl*_*ücü 15

如果您在 Linux 中工作,可能缺少一些扩展,请运行这些命令


sudo apt-get install php-mysql php-pdo

Run Code Online (Sandbox Code Playgroud)


小智 9

如果你想使用Mysql,注释掉这一行,DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" 如果不注释掉另一行