Database
in package
The shared PDO connection, opened on the first query.
Table of Contents
Properties
- $db : PDO|null
Methods
- behind() : bool
- Whether the database lacks migrations the code has.
- connect() : PDO
- Open a connection to the database the `DB_*` settings name.
- dsn() : string
- Build a MySQL DSN.
- options() : array<int, bool|int|string>
- The PDO options of a connection.
- sslConflict() : string
- The `DB_SSL_*` settings another one leaves without effect, as a warning for the operator.
- sslHint() : string
- What to check when a connection over TLS fails.
- db() : PDO
- The shared database connection, opened on first use.
- mysql() : int
- A pdo_mysql attribute by its name.
- socket() : bool
- Whether a host is reached over a Unix socket: a socket path, or `localhost`, which uses the default one.
Properties
$db
private
static PDO|null
$db
= \null
The shared connection; null until the first query.
Methods
behind()
Whether the database lacks migrations the code has.
public
static behind() : bool
Tags
Return values
boolconnect()
Open a connection to the database the `DB_*` settings name.
public
static connect() : PDO
The charset is utf8mb4 and the timezone is the server's.
Tags
Return values
PDO —The connection, with options().
dsn()
Build a MySQL DSN.
public
static dsn(string $host, int $port, string $name) : string
Parameters
- $host : string
-
Host name or IP address, or the path of a Unix socket (it starts with
/). - $port : int
-
TCP port, left out of the DSN when it is MySQL's default (3306) and ignored for a socket.
- $name : string
-
Database name.
Return values
string —The PDO DSN, with the utf8mb4 charset.
options()
The PDO options of a connection.
public
static options(string $host, bool $ssl, bool $verify, string $ca) : array<int, bool|int|string>
Errors throw, and prepared statements are native, so integer columns come back as int. Over TCP the connection
is encrypted, unless $ssl is off; over a Unix socket TLS does not work.
Parameters
- $host : string
-
Host name or IP address, or a socket path;
localhostconnects over the default socket. - $ssl : bool
-
Whether to encrypt over TCP.
- $verify : bool
-
Whether to verify the server's certificate, name included.
- $ca : string
-
CA file to verify it against; '' for the CAs the system trusts.
Return values
array<int, bool|int|string> —The options.
sslConflict()
The `DB_SSL_*` settings another one leaves without effect, as a warning for the operator.
public
static sslConflict(string $host, bool $ssl, bool $verify, string $ca) : string
Parameters
- $host : string
-
Host name or IP address, or a socket path, as for
options(). - $ssl : bool
-
Whether to encrypt over TCP.
- $verify : bool
-
Whether to verify the server's certificate.
- $ca : string
-
CA file to verify it against.
Return values
string —The warning; '' when every setting takes effect.
sslHint()
What to check when a connection over TLS fails.
public
static sslHint(string $error, array<int, bool|int|string> $options) : string
mysqlnd gives one message for every certificate that does not verify, readable CA or not, and reports a server without TLS as gone away.
Parameters
- $error : string
-
The connection's error message.
- $options : array<int, bool|int|string>
-
Its options,
options()'s.
Return values
string —The setting to check, as a sentence; '' when TLS is not why.
db()
The shared database connection, opened on first use.
protected
final static db() : PDO
Building, validating or formatting a model therefore needs no database. With DEBUG on, statements are created as DebugStatement so every query execution is timed.
Tags
Return values
PDO —The shared connection, opened by connect().
mysql()
A pdo_mysql attribute by its name.
private
static mysql(string $name) : int
Parameters
- $name : string
-
The name after
ATTR_, such as 'SSL_CA'.
Return values
int —The attribute.
socket()
Whether a host is reached over a Unix socket: a socket path, or `localhost`, which uses the default one.
private
static socket(string $host) : bool
Parameters
- $host : string
-
Host name or IP address, or a socket path.