2017-07-07 49 views
0

我在Laravel 5.4中配置我的postgresql驅動程序以部署到Heroku。這裏是我的config/database.php中,該default已設置爲pgsqlheroku部署中的非法字符串偏移

'pgsql' => [ 
     'driver' => 'pgsql', 
     'host' => parse_url(getenv("DATABASE_URL"))['host'], 
     'database' => substr(parse_url(getenv("DATABASE_URL"))['path'], 1), 
     'username' => parse_url(getenv("DATABASE_URL")['username']), 
     'password' => parse_url(getenv("DATABASE_URL")['password']), 
     'charset' => 'utf8', 
     'prefix' => '', 
     'schema' => 'public', 
    ], 

當我承諾我看到這個警告

PHP Warning: Illegal string offset 'username' in app/config/database.php on line 62 

當運行heroku run php artisan serve我得到一個錯誤

[Symfony\Component\Debug\Exception\FatalThrowableError] 
Type error: PDO::__construct() expects parameter 2 to be string, array given 

這是我的.env

DB_CONNECTION=pgsql 
DB_HOST=127.0.0.1 
DB_PORT=5432 
DB_DATABASE=forge 
DB_USERNAME=postgres 
DB_PASSWORD= 

回答

0

如果您想從提供的.env獲取正確的數據,您的配置數組應該如下所示。

'pgsql' => [ 
      'driver' => 'pgsql', 
      'host' => env('DB_HOST', '127.0.0.1'), 
      'port' => env('DB_PORT', '5432'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'prefix' => '', 
      'schema' => 'public', 
      'sslmode' => 'prefer', 
     ]