Connection extends Connection implements LoggerAwareInterface uses LoggerAwareTrait

Table of Contents

Interfaces

LoggerAwareInterface

Constants

PARAM_BOOL  = \PDO::PARAM_BOOL
Represents a boolean data type.
PARAM_INT  = \PDO::PARAM_INT
Represents a SQL INTEGER data type.
PARAM_LOB  = \PDO::PARAM_LOB
Represents a SQL large object data type.
PARAM_NULL  = \PDO::PARAM_NULL
Represents a SQL NULL data type.
PARAM_STMT  = \PDO::PARAM_STMT
Represents a recordset type. Not currently supported by any drivers.
PARAM_STR  = \PDO::PARAM_STR
Represents a SQL CHAR, VARCHAR data type.

Properties

$_expr  : ExpressionBuilder

Methods

__construct()  : mixed
Initializes a new instance of the Connection class.
bulkInsert()  : int
Bulk inserts table rows with specified data.
connect()  : bool
Gets the DatabasePlatform for the connection and initializes custom types and event listeners.
count()  : int
Executes an SQL SELECT COUNT() statement on a table and returns the count result.
createQueryBuilder()  : QueryBuilder
Creates a new instance of a SQL query builder.
delete()  : int
Executes an SQL DELETE statement on a table.
escapeLikeWildcards()  : string
Quotes like wildcards for given string value.
getExpressionBuilder()  : ExpressionBuilder
Gets the ExpressionBuilder for the connection.
getSchemaInformation()  : SchemaInformation
getServerVersion()  : string
Returns the version of the current platform if applicable.
insert()  : int
Inserts a table row with specified data.
lastInsertId()  : string
Returns the ID of the last inserted row or sequence value.
prepareConnection()  : mixed
Execute commands after initializing a new connection.
quoteColumnValuePairs()  : array<string|int, mixed>
Quotes an associative array of column-value so the column names can be safely used, even if the name is a reserved name.
quoteIdentifier()  : string
Quotes a string so it can be safely used as a table or column name, even if it is a reserved name.
quoteIdentifiers()  : array<string|int, mixed>
Quotes an array of column names so it can be safely used, even if the name is a reserved name.
select()  : Result
Executes an SQL SELECT statement on a table.
truncate()  : int
Executes an SQL TRUNCATE statement on a table.
update()  : int
Executes an SQL UPDATE statement on a table.
ensureDatabaseValueTypes()  : void
This method ensures that data values a properly converted to their database equivalent.
quoteColumnTypes()  : array<string|int, mixed>
Detect if the column types are specified by column name or using positional information. In the first case quote the field names accordingly.

Constants

PARAM_BOOL

Represents a boolean data type.

public mixed PARAM_BOOL = \PDO::PARAM_BOOL

PARAM_INT

Represents a SQL INTEGER data type.

public mixed PARAM_INT = \PDO::PARAM_INT

PARAM_LOB

Represents a SQL large object data type.

public mixed PARAM_LOB = \PDO::PARAM_LOB

PARAM_NULL

Represents a SQL NULL data type.

public mixed PARAM_NULL = \PDO::PARAM_NULL

PARAM_STMT

Represents a recordset type. Not currently supported by any drivers.

public mixed PARAM_STMT = \PDO::PARAM_STMT

PARAM_STR

Represents a SQL CHAR, VARCHAR data type.

public mixed PARAM_STR = \PDO::PARAM_STR

Properties

Methods

__construct()

Initializes a new instance of the Connection class.

public __construct(array<string|int, mixed> $params, Driver $driver[, Configuration|null $config = null ][, EventManager|null $em = null ]) : mixed
Parameters
$params : array<string|int, mixed>

The connection parameters.

$driver : Driver

The driver to use.

$config : Configuration|null = null

The configuration, optional.

$em : EventManager|null = null

The event manager, optional.

Tags
throws
Exception

bulkInsert()

Bulk inserts table rows with specified data.

public bulkInsert(string $tableName, array<string|int, mixed> $data[, array<string|int, mixed> $columns = [] ][, array<string|int, mixed> $types = [] ]) : int

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$tableName : string

The name of the table to insert data into.

$data : array<string|int, mixed>

An array containing associative arrays of column-value pairs or just the values to be inserted.

$columns : array<string|int, mixed> = []

An array containing the column names of the data which should be inserted.

$types : array<string|int, mixed> = []

Types of the inserted data.

Return values
int

The number of affected rows.

connect()

Gets the DatabasePlatform for the connection and initializes custom types and event listeners.

public connect() : bool
Return values
bool

count()

Executes an SQL SELECT COUNT() statement on a table and returns the count result.

public count(string $item, string $tableName, array<string|int, mixed> $identifiers) : int
Parameters
$item : string

The column/expression of the table which to count

$tableName : string

The name of the table on which to count.

$identifiers : array<string|int, mixed>

The selection criteria. An associative array containing column-value pairs.

Return values
int

The number of rows counted

delete()

Executes an SQL DELETE statement on a table.

public delete(string $tableName, array<string|int, mixed> $identifier[, array<string|int, mixed> $types = [] ]) : int

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$tableName : string

The name of the table on which to delete.

$identifier : array<string|int, mixed>

The deletion criteria. An associative array containing column-value pairs.

$types : array<string|int, mixed> = []

The types of identifiers.

Return values
int

The number of affected rows.

escapeLikeWildcards()

Quotes like wildcards for given string value.

public escapeLikeWildcards(string $value) : string
Parameters
$value : string

The value to be quoted.

Return values
string

The quoted value.

getServerVersion()

Returns the version of the current platform if applicable.

public getServerVersion() : string

If no version information is available only the platform name will be shown. If the platform name is unknown or unsupported the driver name will be shown.

Internal
Return values
string

insert()

Inserts a table row with specified data.

public insert(string $tableName, array<string|int, mixed> $data[, array<string|int, mixed> $types = [] ]) : int

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$tableName : string

The name of the table to insert data into.

$data : array<string|int, mixed>

An associative array containing column-value pairs.

$types : array<string|int, mixed> = []

Types of the inserted data.

Return values
int

The number of affected rows.

lastInsertId()

Returns the ID of the last inserted row or sequence value.

public lastInsertId([string|null $tableName = null ][, string $fieldName = 'uid' ]) : string

If table and fieldname have been provided it tries to build the sequence name for PostgreSQL. For MySQL the parameters are not required / and only the table name is passed through.

Parameters
$tableName : string|null = null
$fieldName : string = 'uid'
Return values
string

prepareConnection()

Execute commands after initializing a new connection.

public prepareConnection(string $commands) : mixed
Parameters
$commands : string

quoteColumnValuePairs()

Quotes an associative array of column-value so the column names can be safely used, even if the name is a reserved name.

public quoteColumnValuePairs(array<string|int, mixed> $input) : array<string|int, mixed>

Delimiting style depends on the underlying database platform that is being used.

Parameters
$input : array<string|int, mixed>
Return values
array<string|int, mixed>

quoteIdentifier()

Quotes a string so it can be safely used as a table or column name, even if it is a reserved name.

public quoteIdentifier(string $identifier) : string

EXAMPLE: tableName.fieldName => "tableName"."fieldName"

Delimiting style depends on the underlying database platform that is being used.

Parameters
$identifier : string

The name to be quoted.

Return values
string

The quoted name.

quoteIdentifiers()

Quotes an array of column names so it can be safely used, even if the name is a reserved name.

public quoteIdentifiers(array<string|int, mixed> $input) : array<string|int, mixed>

Delimiting style depends on the underlying database platform that is being used.

Parameters
$input : array<string|int, mixed>
Return values
array<string|int, mixed>

select()

Executes an SQL SELECT statement on a table.

public select(array<string|int, string> $columns, string $tableName[, array<string|int, mixed> $identifiers = [] ][, array<string|int, string> $groupBy = [] ][, array<string|int, mixed> $orderBy = [] ][, int $limit = 0 ][, int $offset = 0 ]) : Result

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$columns : array<string|int, string>

The columns of the table which to select.

$tableName : string

The name of the table on which to select.

$identifiers : array<string|int, mixed> = []

The selection criteria. An associative array containing column-value pairs.

$groupBy : array<string|int, string> = []

The columns to group the results by.

$orderBy : array<string|int, mixed> = []

Associative array of column name/sort directions pairs.

$limit : int = 0

The maximum number of rows to return.

$offset : int = 0

The first result row to select (when used with limit)

Return values
Result

The executed statement.

truncate()

Executes an SQL TRUNCATE statement on a table.

public truncate(string $tableName[, bool $cascade = false ]) : int

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$tableName : string

The name of the table to truncate.

$cascade : bool = false

Not supported on many platforms but would cascade the truncate by following foreign keys.

Return values
int

The number of affected rows. For a truncate this is unreliable as there is no meaningful information.

update()

Executes an SQL UPDATE statement on a table.

public update(string $tableName, array<string|int, mixed> $data, array<string|int, mixed> $identifier[, array<string|int, mixed> $types = [] ]) : int

All SQL identifiers are expected to be unquoted and will be quoted when building the query.

Parameters
$tableName : string

The name of the table to update.

$data : array<string|int, mixed>

An associative array containing column-value pairs.

$identifier : array<string|int, mixed>

The update criteria. An associative array containing column-value pairs.

$types : array<string|int, mixed> = []

Types of the merged $data and $identifier arrays in that order.

Return values
int

The number of affected rows.

ensureDatabaseValueTypes()

This method ensures that data values a properly converted to their database equivalent.

protected ensureDatabaseValueTypes(string $tableName, array<string|int, mixed> &$data, array<string|int, mixed> &$types) : void

Additionally, it adds the proper types to the type-array, if this has no manual preset types. Note: Types are only added if not given externally.

Parameters
$tableName : string
$data : array<string|int, mixed>
$types : array<string|int, mixed>
Internal

Should be private, but mocked in tests currently.

quoteColumnTypes()

Detect if the column types are specified by column name or using positional information. In the first case quote the field names accordingly.

protected quoteColumnTypes(array<string|int, mixed> $input) : array<string|int, mixed>
Parameters
$input : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results