I am using the following connection to connect to Postgres SQL without Database as I need to fetch all the database names later for configuration
try{
$this->connection = new \PDO($this->database.":host=".$this->host,$this->user,$this->password);
$this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $this->connection;
}catch(\PDOException $e){
echo $e->getMessage();
}
But I am getting the following error
SQLSTATE[08006] [7] FATAL: database "admin" does not exist
The following are the values that are set in the properties:
$this->database = pgsql
$this->host = localhost
$this->user = admin
$this->password = admin
Can anyone please help me out how to connect to Postgres SQL without any database selection with PHP PDO
postgresto connect to further list databases