我正在Laravel 5.4中配置我的postgresql驱动程序以部署到Heroku。这是我的config / database.php,default
已设置为pgsql
'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 :(得分: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',
]
答案 1 :(得分:0)
我在这个网站找到了答案。它也迎合了mysql和sqlite,请阅读 https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku