2016-07-28 146 views
1

我正在使用Symfony/Silex SecurityServiceProvider登录该网站上的用户。SQLSTATE [08006] [7]无法将主机名“dbname =”转换为地址

http://silex.sensiolabs.org/doc/providers/security.html 

我跟着一步导引门槛,但是当我提交登录表单,我有一个PostgreSQL错误

SQLSTATE[08006] [7] could not translate host name "dbname=" to address 

不管我了DBNAME设置,我还是得到了错误。即使使用远程服务器的正确IP也是如此。不过,我的设置很好,因为我使用相同的类来连接和请求服务器,并且它始终工作。

该错误只在提交登录表单时出现!

我的登录类

<?php 

namespace Model; 

use Silex\Application; 

abstract class Entity { 

    private $app; 
    private $host; 
    private $base; 
    private $port; 
    private $user; 
    private $pass; 
    private $charset; 

    public function __construct(Application $app) 
    { 
     $this->app = $app; 

     $this->host = $app['config']['database']['host']; 
     $this->base = $app['config']['database']['base']; 
     $this->port = $app['config']['database']['port']; 
     $this->user = $app['config']['database']['user']; 
     $this->pass = $app['config']['database']['pass']; 
     $this->charset = $app['config']['database']['charset']; 
    } 

    protected function connectBDD() 
    { 
     $connect = new \PDO("pgsql:host=$this->host;dbname=$this->base", $this->user, $this->pass); 
     $connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); 
     $connect->query("SET NAMES '$this->charset'"); 

     return $connect; 
    } 
} 
} 

感谢您的帮助

回答

2

您配置值是空的。 $app['config']['database']['host']是空的,连接看起来像$connect = new \PDO("pgsql:host=;dbname=", ...);
试图转储配置看值

public function __construct(Application $app) 
{ 
    dump($app['config']['database']); 
    ... 
} 
+0

事实上,孩子的构造破碎的父类的构造... – Macbernie