Documentation

ConnectionTrait

Trait for getting static connections

Table of Contents

$crud  : array<string, PdoCrud>
Named connections to DB
getConnection()  : PdoCrud
Method returns database connection If you will pas array of connection names, then the first existing one will be returned
setConnection()  : void
Method sets connection
constructConnection()  : PdoCrud
Contructing connection to database object
dsnExists()  : bool
Method returns true if the connection exists, false otherwise
getConnectionForArray()  : PdoCrud
Method returns database connection
getConnectionScalar()  : PdoCrud
Method returns database connection If you will pas array of connection names, then the first existing one will be returned
validateDsn()  : void
Method validates dsn fields

Properties

Methods

getConnection()

Method returns database connection If you will pas array of connection names, then the first existing one will be returned

public static getConnection([string|array<string|int, string>|mixed $connectionName = 'default-db-connection' ]) : PdoCrud
Parameters
$connectionName : string|array<string|int, string>|mixed = 'default-db-connection'

connection name or array of connection names

Return values
PdoCrud

connection

setConnection()

Method sets connection

public static setConnection(PdoCrud|null $connection[, string $connectionName = 'default-db-connection' ]) : void
Parameters
$connection : PdoCrud|null

new connection or it's mock

$connectionName : string = 'default-db-connection'

connection name

Return values
void

constructConnection()

Contructing connection to database object

private static constructConnection() : PdoCrud
Tags
codeCoverageIgnore
Return values
PdoCrud

connection object wich is no initialized

dsnExists()

Method returns true if the connection exists, false otherwise

private static dsnExists(string $connectionName) : bool
Parameters
$connectionName : string

connection name

Return values
bool

true if the connection exists, false otherwise

getConnectionForArray()

Method returns database connection

private static getConnectionForArray(array<string|int, string> $connectionName) : PdoCrud
Parameters
$connectionName : array<string|int, string>

connection names

Return values
PdoCrud

connection

getConnectionScalar()

Method returns database connection If you will pas array of connection names, then the first existing one will be returned

private static getConnectionScalar([string $connectionName = 'default-db-connection' ]) : PdoCrud
Parameters
$connectionName : string = 'default-db-connection'

Connection name or array of connection names

Return values
PdoCrud

connection

validateDsn()

Method validates dsn fields

private static validateDsn(string $connectionName) : void
Parameters
$connectionName : string

connection name

Return values
void

Search results