0 follower

Final Class Yiisoft\Db\Sqlite\Dsn

InheritanceYiisoft\Db\Sqlite\Dsn
ImplementsStringable

Represents a Data Source Name (DSN) for a SQLite 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 'sqlite'

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $driver 'sqlite', string $databaseName '' )
$driver string

The database driver name.

$databaseName string

The database name to connect to. It can be

  • absolute file path for a file database;
  • 'memory' for a database in memory;
  • empty string for a temporary file database which is deleted when the connection is closed.

                public function __construct(
    public readonly string $driver = 'sqlite',
    public readonly string $databaseName = '',
) {}

            
__toString() public method

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 driver property is used as the driver prefix of the DSN. For example:

$dsn = new Dsn('sqlite', __DIR__ . '/data/test.sq3');
$driver = new Driver($dsn);
$db = new Connection($driver, $schemaCache);

Will result in the DSN string sqlite:/path/to/data/test.sq3.

                public function __toString(): string
{
    if ($this->databaseName === 'memory') {
        return "$this->driver::memory:";
    }
    return "$this->driver:$this->databaseName";
}