0 follower

Final Class Yiisoft\Db\Oracle\Dsn

InheritanceYiisoft\Db\Oracle\Dsn
ImplementsStringable

Represents a Data Source Name (DSN) for an Oracle Server that's used to configure a {@see Driver} instance.

To get DSN in string format, use the (string) type casting operator.

Property Details

Hide inherited properties

$databaseName public property
public string $databaseName ''
$driver public property
public string $driver 'oci'
$host public property
public string $host '127.0.0.1'
$options public property
public array $options = []
$port public property
public string $port '1521'

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $driver 'oci', string $host '127.0.0.1', string $databaseName '', string $port '1521', array $options = [] )
$driver string
$host string
$databaseName string
$port string
$options array

                public function __construct(
    public readonly string $driver = 'oci',
    public readonly string $host = '127.0.0.1',
    public readonly string $databaseName = '',
    public readonly string $port = '1521',
    public readonly array $options = [],
) {}

            
__toString() public method

public string __toString ( )
return string

The Data Source Name, or DSN, contains the information required to connect to the database.

Please refer to the PHP manual on the format of the DSN string.

The driver property is used as the driver prefix of the DSN. For example:

$dsn = new Dsn('oci', 'localhost', 'yiitest', '1521', ['charset' => 'AL32UTF8']);
$driver = new Driver($dsn, 'username', 'password');
$connection = new Connection($driver, 'system', 'root');

Will result in the DSN string oci:dbname=localhost:1521/yiitest;charset=AL32UTF8.

                public function __toString(): string
{
    $dsn = "$this->driver:dbname=$this->host:$this->port";
    if ($this->databaseName !== '') {
        $dsn .= "/$this->databaseName";
    }
    foreach ($this->options as $key => $value) {
        $dsn .= ";$key=$value";
    }
    return $dsn;
}