I have laravel app that run with two database. database_1 in local server, and database_2 in erp server.
When i tried to get data from database 2, i get the following
SQLSTATE[08006] [7] FATAL: password authentication failed for user "postgres" FATAL: password
authentication failed for user "postgres"
There is my .env
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=infinite-mob
DB_USERNAME=postgres
DB_PASSWORD=password
DB_CONNECTION_2=pgsql
DB_HOST_2=35.185.179.247
DB_PORT_2=5432
DB_DATABASE_2=infinite
DB_USERNAME_2=ics_mobile
DB_PASSWORD_2=password
There is my config/database.php
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'infinite-mob'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'pgsql2' => [
'driver' => 'pgsql',
'host' => env('DB_HOST_2', '35.185.179.247'),
'port' => env('DB_PORT_2', '5432'),
'database' => env('DB_DATABASE_2', 'infinite'),
'username' => env('DB_USERNAME', 'ics_mobile'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
Did anyone know what's the problem is ?
CodePudding user response:
In your model did you add this?
protected $connection = 'pgsql2';
And in pgsql2 your username and password is wrong, must be;
'pgsql2' => [
'driver' => 'pgsql',
'host' => env('DB_HOST_2', '35.185.179.247'),
'port' => env('DB_PORT_2', '5432'),
'database' => env('DB_DATABASE_2', 'infinite'),
'username' => env('DB_USERNAME_2', 'ics_mobile'),
'password' => env('DB_PASSWORD_2', 'password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]