Doctrine 找不到 PostgreSQL PDO 驱动程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13627938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:35:42  来源:igfitidea点击:

Doctrine can't find the PostgreSQL PDO driver?

phppostgresqlsymfonydoctrine

提问by Phill Pafford

I see this question is very similar but I have PDO and pdo_pgsql installed

我看到这个问题非常相似,但我安装了 PDO 和 pdo_pgsql

Here is my error message:

这是我的错误信息:

 php app/console doctrine:mapping:convert yml ./src/Vendor/Bundle/MyBundle/Resources/config/doctrine/metadata/orm --from-database --force



  [PDOException]         
  could not find driver  



doctrine:mapping:convert [--filter="..."] [--force] [--from-database] [--extend[="..."]] [--num-spaces[="..."]] [--namespace[="..."]] [--em[="..."]] to-type dest-path 

Here is my config.yml settings

这是我的 config.yml 设置

doctrine:
    dbal:
      connections:
        my_database:
          driver:   pdo_pgsql
          port:     5432
          dbname:   blah
          user:     foo
          password: bar
          charset:  UTF8

The host is configured in the prod and dev yaml files like this

主机在 prod 和 dev yaml 文件中是这样配置的

doctrine:
    dbal:
      connections:
        my_database:
          host: localhost

running php -mon the command line I see that PDO, pdo_pgsql and pgsql are all installed

php -m在命令行运行我看到PDO,pdo_pgsql和pgsql都安装了

PDO
pdo_pgsql
pgsql

What am I missing?

我错过了什么?

回答by Phill Pafford

Ugh..

啊..

You have to setup the default database first in the parameters.yml file

您必须首先在 parameters.yml 文件中设置默认数据库

Well that's what worked for me

嗯,这对我有用

回答by Jorge Pirela

In Symfony 2.7 or more the problem is resolved by editing the app/config/config.ymlfile to leave it to the database which indicates the driver:

在 Symfony 2.7 或更高版本中,通过编辑app/config/config.yml文件将其留给指示驱动程序的数据库来解决问题:

doctrine:
    dbal:
        driver: "%database_driver%"

This solution is also useful when multiple databases of different drivers are used, for example, a MySQL database , another PostgreSQL database, ...

当使用不同驱动程序的多个数据库时,此解决方案也很有用,例如,一个 MySQL 数据库,另一个 PostgreSQL 数据库,...

回答by Luma Macagnan

First of all, verify your php.inifile: the extensions php_pdo_pgsqland php_pdomust be enabled. Make sure you apply this changes on php.ini file that your symfony projectis using (I imagine you are using the tool app/console from symfony), check this on localhost/path_to_your_project/web/config.php. You know if this extensions are enabled executing the function phpinfo().

首先,验证您的php.ini文件:必须启用扩展php_pdo_pgsqlphp_pdo。确保您在symfony 项目正在使用的php.ini 文件上应用此更改(我想您正在使用来自 symfony 的工具 app/console),在localhost/path_to_your_project/web/config.php 上进行检查。您知道是否启用了此扩展来执行函数 phpinfo()。

This command is also helpfull: php -m. It lists on console all the php modules that are loaded.

这个命令也很有帮助:php -m。它在控制台上列出了所有加载的 php 模块。

Tip: check out you Apache error log, there could be something wrong with the load of your extensions. This file is located according to your server configuration.

提示:检查您的Apache 错误日志,您的扩展负载可能有问题。该文件的位置取决于您的服务器配置。