Documentation

CPdoConnectionManager
in package
implements IConnectionManager

PDO implementation of the connection manager.

Manages database connections using PDO, supporting multiple DBMS types.

Table of Contents

Interfaces

IConnectionManager
Interface for managing database connections pool.

Properties

$autocommit  : bool
$connection_params  : array<string, array<string|int, mixed>>
$connections  : array<string, PDO>
$dbms_sub_type  : string
$default_key  : string|null

Methods

__construct()  : mixed
Constructor
Connect()  : mixed
Establishes a new database connection.
Disconnect()  : void
Closes a specific database connection.
DisconnectAll()  : void
Closes all open database connections.
GetConnection()  : mixed
Retrieves a database connection handle.
GetConnectionError()  : int
Gets the last error number for a connection.
GetConnectionErrorString()  : string
Gets the last error string for a connection.
GetDbmsType()  : string
Get the name of DBMS used
GetDefaultKey()  : string|null
Gets the current default connection key.
HasConnection()  : bool
Checks if a connection exists and is active.
RealConnection()  : bool
Performs the actual connection based on the current parameters.
SetAutoCommit()  : void
Sets autocommit mode for connections.
SetDefaultKey()  : void
Sets the default connection key.
BuildDsn()  : string
Builds a PDO DSN string based on the DBMS sub-type and connection parameters.
RealConnectionForKey()  : bool
Performs actual connection for a specific key.

Properties

$connection_params

protected array<string, array<string|int, mixed>> $connection_params = []

Stored parameters for lazy connections

Methods

__construct()

Constructor

public __construct([string $dbms_sub_type = 'mysql' ]) : mixed
Parameters
$dbms_sub_type : string = 'mysql'

The underlying DBMS type (mysql, pgsql, sqlsrv, oci)

Connect()

Establishes a new database connection.

public Connect(string $dbname, string $username, string $pwd, string $hostname, int|string $port) : mixed
Parameters
$dbname : string

Database name

$username : string

Database username

$pwd : string

Database password

$hostname : string

Database host

$port : int|string

Database port

Return values
mixed —

The connection handle

Disconnect()

Closes a specific database connection.

public Disconnect([string|null $connectionKey = null ]) : void
Parameters
$connectionKey : string|null = null

Connection identifier key, null for default

GetConnection()

Retrieves a database connection handle.

public GetConnection([string|null $connectionKey = null ]) : mixed
Parameters
$connectionKey : string|null = null

Connection identifier key, null for default

Return values
mixed —

The connection handle or null if not connected

GetConnectionError()

Gets the last error number for a connection.

public GetConnectionError([string|null $connectionKey = null ]) : int
Parameters
$connectionKey : string|null = null

Connection identifier key, null for default

Return values
int —

Error number, 0 if no error

GetConnectionErrorString()

Gets the last error string for a connection.

public GetConnectionErrorString([string|null $connectionKey = null ]) : string
Parameters
$connectionKey : string|null = null

Connection identifier key, null for default

Return values
string —

Error message

GetDbmsType()

Get the name of DBMS used

public GetDbmsType() : string
Return values
string —

the name of DBMS used. i.e.: mysql, oracle, postgresql (the convention is all in lowercase)

GetDefaultKey()

Gets the current default connection key.

public GetDefaultKey() : string|null
Return values
string|null —

The default connection key or null

HasConnection()

Checks if a connection exists and is active.

public HasConnection([string|null $connectionKey = null ]) : bool
Parameters
$connectionKey : string|null = null

Connection identifier key, null for default

Return values
bool —

True if connected, false otherwise

RealConnection()

Performs the actual connection based on the current parameters.

public RealConnection() : bool
Return values
bool —

True if connection successful

SetAutoCommit()

Sets autocommit mode for connections.

public SetAutoCommit(bool $autocommit) : void
Parameters
$autocommit : bool

True for autocommit, false for manual commit

SetDefaultKey()

Sets the default connection key.

public SetDefaultKey(string $connectionKey) : void
Parameters
$connectionKey : string

The connection key to set as default

BuildDsn()

Builds a PDO DSN string based on the DBMS sub-type and connection parameters.

protected BuildDsn(array<string|int, mixed> $params) : string
Parameters
$params : array<string|int, mixed>

Connection parameters

Return values
string —

The DSN string

RealConnectionForKey()

Performs actual connection for a specific key.

protected RealConnectionForKey(string $key) : bool
Parameters
$key : string

Connection key

Tags
throws
CConnectionException

If connection fails

Return values
bool —

True if successful


        
On this page

Search results