Final Class Yiisoft\Db\Pgsql\Dsn
| Inheritance | Yiisoft\Db\Pgsql\Dsn |
|---|---|
| Implements | Stringable |
Represents a Data Source Name (DSN) for a PostgreSQL Server that's used to configure a {@see Driver} instance.
To get DSN in string format, use the (string) type casting operator.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $databaseName | string | Yiisoft\Db\Pgsql\Dsn | |
| $driver | string | Yiisoft\Db\Pgsql\Dsn | |
| $host | string | Yiisoft\Db\Pgsql\Dsn | |
| $options | array | Yiisoft\Db\Pgsql\Dsn | |
| $port | string | Yiisoft\Db\Pgsql\Dsn |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Pgsql\Dsn | |
| __toString() | Yiisoft\Db\Pgsql\Dsn |
Property Details
Method Details
| public mixed __construct ( string $driver = 'pgsql', string $host = '127.0.0.1', string $databaseName = 'postgres', string $port = '5432', string[] $options = [] ) | ||
| $driver | string |
The database driver name. |
| $host | string |
The database host name or IP address. |
| $databaseName | string |
The database name to connect to. |
| $port | string |
The database port. Empty string if not set. |
| $options | string[] |
The database connection options. Default value to an empty array. |
public function __construct(
public readonly string $driver = 'pgsql',
public readonly string $host = '127.0.0.1',
public readonly string $databaseName = 'postgres',
public readonly string $port = '5432',
public readonly array $options = [],
) {}
| public string __toString ( ) | ||
| return | string |
The Data Source Name, or DSN, has the information required to connect to the database. Please refer to the PHP manual on the format of the DSN string. The
Will result in the DSN string |
|---|---|---|
public function __toString(): string
{
$dsn = "$this->driver:host=$this->host";
if ($this->databaseName !== '') {
$dsn .= ";dbname=$this->databaseName";
}
if ($this->port !== '') {
$dsn .= ";port=$this->port";
}
foreach ($this->options as $key => $value) {
$dsn .= ";$key=$value";
}
return $dsn;
}
Signup or Login in order to comment.