我正在使用以下连接连接到没有数据库的 Postgres SQL,因为我需要稍后获取所有数据库名称以进行配置
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();
}
但我收到以下错误
SQLSTATE[08006] [7] FATAL: database "admin" does not exist
以下是在属性中设置的值:
$this->database = pgsql
$this->host = localhost
$this->user = admin
$this->password = admin
谁能帮我解决如何使用 PHP PDO 在不选择任何数据库的情况下连接到 Postgres SQL
最佳答案
关于php - 如何在不在 PDO 中指定数据库名称的情况下连接到 Postgres 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42112781/