MysqlDSN
Represents a MySQL DSN (Data Source Name) configuration object.
This class provides a convenient and structured way to build MySQL DSN strings used in PDO connections. It supports common connection parameters such as host, port, database name, charset, and optional Unix socket path.
Tags
Table of Contents
Constants
- CHARSET = 'charset'
- DBNAME = 'dbname'
- HOST = 'host'
- PORT = 'port'
- PREFIX = 'mysql:'
- UNIX_SOCKET = 'unixSocket'
Properties
- $charset : string
- Character set used for the connection.
- $dbname : string|null
- Name of the database to connect to.
- $host : string
- Hostname or IP address of the MySQL server.
- $port : int
- Port number on which the MySQL server is listening.
- $unixSocket : string|null
- Optional Unix socket path for local MySQL connections.
Methods
- __construct() : mixed
- Constructs a new MysqlDSN instance.
- __toString() : string
- Builds and returns the DSN string for use with PDO.
- toArray() : array<string, mixed>
- Converts the DSN configuration to an associative array.
Constants
CHARSET
public
mixed
CHARSET
= 'charset'
DBNAME
public
mixed
DBNAME
= 'dbname'
HOST
public
mixed
HOST
= 'host'
PORT
public
mixed
PORT
= 'port'
PREFIX
public
mixed
PREFIX
= 'mysql:'
UNIX_SOCKET
public
mixed
UNIX_SOCKET
= 'unixSocket'
Properties
$charset
Character set used for the connection.
public
string
$charset
$dbname
Name of the database to connect to.
public
string|null
$dbname
$host
Hostname or IP address of the MySQL server.
public
string
$host
$port
Port number on which the MySQL server is listening.
public
int
$port
$unixSocket
Optional Unix socket path for local MySQL connections.
public
string|null
$unixSocket
Methods
__construct()
Constructs a new MysqlDSN instance.
public
__construct([array{charset: string|null, dbname: string|null, host: string|null, port: string|null, unixSocket: string|null} $init = [] ]) : mixed
Parameters
- $init : array{charset: string|null, dbname: string|null, host: string|null, port: string|null, unixSocket: string|null} = []
-
An associative array of parameters to initialize the DSN.
Tags
__toString()
Builds and returns the DSN string for use with PDO.
public
__toString() : string
Tags
Return values
string —The DSN string.
toArray()
Converts the DSN configuration to an associative array.
public
toArray() : array<string, mixed>
Tags
Return values
array<string, mixed> —The configuration as an associative array.