Final Class Yiisoft\Db\Mysql\DsnSocket
| Inheritance | Yiisoft\Db\Mysql\DsnSocket |
|---|---|
| Implements | Stringable |
Represents a Data Source Name (DSN) with unix socket for MySQL and MariaDB servers that's used to configure a Yiisoft\Db\Mysql\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\Mysql\DsnSocket | |
| $driver | string | Yiisoft\Db\Mysql\DsnSocket | |
| $options | array | Yiisoft\Db\Mysql\DsnSocket | |
| $unixSocket | string | Yiisoft\Db\Mysql\DsnSocket |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Mysql\DsnSocket | |
| __toString() | Yiisoft\Db\Mysql\DsnSocket |
Property Details
Method Details
| public __construct( string $driver = 'mysql', string $unixSocket = '/var/run/mysqld/mysqld.sock', string $databaseName = '', string[] $options = [] ): mixed | ||
| $driver | string |
The database driver to use. |
| $unixSocket | string |
The unix socket to connect to. |
| $databaseName | string |
The database name to connect to. |
| $options | string[] |
The options to use. |
public function __construct(
public readonly string $driver = 'mysql',
public readonly string $unixSocket = '/var/run/mysqld/mysqld.sock',
public readonly string $databaseName = '',
public readonly array $options = [],
) {}
| public __toString( ): string | ||
| 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:unix_socket=$this->unixSocket";
if ($this->databaseName !== '') {
$dsn .= ";dbname=$this->databaseName";
}
foreach ($this->options as $key => $value) {
$dsn .= ";$key=$value";
}
return $dsn;
}
Signup or Login in order to comment.