Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 3.0控制台识别环境变量_Php_Console_Doctrine_Symfony - Fatal编程技术网

Php Symfony 3.0控制台识别环境变量

Php Symfony 3.0控制台识别环境变量,php,console,doctrine,symfony,Php,Console,Doctrine,Symfony,我在vhost上设置了一些环境变量: <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, t

我在vhost上设置了一些环境变量:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog /home/pcmagas/Kwdikas/web/apps/logs/error.log
    CustomLog /home/pcmagas/Kwdikas/web/apps/logs/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /symphotest /home/pcmagas/Kwdikas/web/apps/symphotest/web
    <Directory /home/pcmagas/Kwdikas/web/apps/symphotest/web>
        AllowOverride All
        Require all granted

        DirectoryIndex appp_dev.php
    </Directory>


    <Directory /home/pcmagas/Kwdikas/web/apps/symphotest>
    SetEnv OPENSHIFT_POSTGRESQL_DB_HOST localhost
    SetEnv OPENSHIFT_POSTGRESQL_DB_PORT 5432
    SetEnv OPENSHIFT_APP_NAME sampledb
    SetEnv OPENSHIFT_POSTGRESQL_DB_USERNAME sampleuser
    SetEnv OPENSHIFT_POSTGRESQL_DB_PASSWORD samplepasswd
    </Directory>
</VirtualHost>
我通过定制的环境变量配置db连接: config.yml:

imports:
    - { resource: params.php }
    - { resource: security.yml }
    - { resource: services.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id:  session.handler.native_file
        save_path:   "%kernel.root_dir%/sessions/%kernel.environment%"
    fragments:       ~
    http_method_override: true
    assets: ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    encryption: "%mailer_encryption_method%"
    port: "%mailer_port%"
    spool:     { type: memory }


<?php
  $container->setParameter('secret','himitsu');

  // Db Parameters
  $container->setParameter('database_driver','pdo_pgsql');
  $container->setParameter('database_host', getenv("OPENSHIFT_POSTGRESQL_DB_HOST"));
  $container->setParameter('database_port', getenv("OPENSHIFT_POSTGRESQL_DB_PORT"));
  $container->setParameter('database_name', getenv("OPENSHIFT_APP_NAME"));
  $container->setParameter('database_user', getenv("OPENSHIFT_POSTGRESQL_DB_USERNAME"));
  $container->setParameter('database_password', getenv("OPENSHIFT_POSTGRESQL_DB_PASSWORD"));
我得到以下错误:

  [Doctrine\DBAL\Exception\ConnectionException]                                                  
  An exception occured in driver: SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  



  [Doctrine\DBAL\Driver\PDOException]                            
  SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  



  [PDOException]                                                 
  SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  


doctrine:schema:create [--dump-sql] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
[条令\DBAL\Exception\ConnectionException]
驱动程序中发生异常:SQLSTATE[08006][7]致命:数据库“user=''”不存在
[条令\DBAL\Driver\PDOException]
SQLSTATE[08006][7]致命:数据库“user=''”不存在
[例外情况]
SQLSTATE[08006][7]致命:数据库“user=''”不存在
条令:模式:创建[--dump sql][--em[em][-h|--help][-q|--quiet][v|vv|vv|--verbose][v|--version][--ansi][--no-ansi][n|--无交互][e|--env-env][--无调试][]

您知道如何管理控制台来读取环境变量吗?

我必须为数据库用户设置密码


我忘记使用数据库密码正确设置数据库,因此出现连接错误。

我必须为数据库用户设置密码


我忘了用数据库密码正确设置数据库,因此出现了连接错误。

这使得原始问题“无法重现或简单的印刷错误”。这使得原始问题“无法重现或简单的印刷错误”。OP已将密码设置为数据库用户。请参阅下面的答案。OP已将密码设置为数据库用户。见下面的答案。
php ./bin/console doctrine:schema:create
  [Doctrine\DBAL\Exception\ConnectionException]                                                  
  An exception occured in driver: SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  



  [Doctrine\DBAL\Driver\PDOException]                            
  SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  



  [PDOException]                                                 
  SQLSTATE[08006] [7] FATAL:  database "user=''" does not exist  


doctrine:schema:create [--dump-sql] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>