Connection

class \TYPO3\CMS\Core\Database\Connection

Extends
Connection
Implements
LoggerAwareInterface
Uses
LoggerAwareTrait

Table of Contents

Interfaces

LoggerAwareInterface

Constants

PARAM_BOOL  : mixed = \Doctrine\DBAL\ParameterType::BOOLEAN
Represents a boolean data type.
PARAM_INT  : mixed = \Doctrine\DBAL\ParameterType::INTEGER
Represents a SQL INTEGER data type.
PARAM_INT_ARRAY  : mixed = \Doctrine\DBAL\ArrayParameterType::INTEGER
Represents an array of integer values.
PARAM_LOB  : mixed = \Doctrine\DBAL\ParameterType::LARGE_OBJECT
Represents a SQL large object data type.
PARAM_NULL  : mixed = \Doctrine\DBAL\ParameterType::NULL
Represents a SQL NULL data type.
PARAM_STR  : mixed = \Doctrine\DBAL\ParameterType::STRING
Represents a SQL CHAR, VARCHAR data type.
PARAM_STR_ARRAY  : mixed = \Doctrine\DBAL\ArrayParameterType::STRING
Represents an array of string values.

Methods

__construct()  : mixed
Initializes a new instance of the Connection class.
bulkInsert()  : int
Bulk inserts table rows with specified data.
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.
getPlatformServerVersion()  : string
Returns the version of the current platform if applicable, containing the platform as prefix.
getSchemaInformation()  : SchemaInformation
insert()  : int
Inserts a table row with specified data.
lastInsertId()  : numeric-string
Returns the ID of the last inserted row.
prepareConnection()  : void
Execute commands after initializing a new connection.
quoteColumnValuePairs()  : array
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
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.
transactional()  : T
Executes a function in a transaction.
truncate()  : int
Executes an SQL TRUNCATE statement on a table.
update()  : int
Executes an SQL UPDATE statement on a table.
connect()  : Connection
Gets the DatabasePlatform for the connection and initializes custom types and event listeners.
ensureDatabaseValueTypes()  : void
This method ensures that data values a properly converted to their database equivalent.
quoteColumnTypes()  : array
Detect if the column types are specified by column name or using positional information. In the first case quote the field names accordingly.
typo3_getServerVersionProvider()  : ServerVersionProvider
Returns the suitable `ServerVersionProvider`, which could be the connection itself or a `StaticServerVersionProvider` based on either of following configuration values:

Constants

PARAM_BOOL

Represents a boolean data type.

public mixed PARAM_BOOL = \Doctrine\DBAL\ParameterType::BOOLEAN

PARAM_INT

Represents a SQL INTEGER data type.

public mixed PARAM_INT = \Doctrine\DBAL\ParameterType::INTEGER

PARAM_INT_ARRAY

Represents an array of integer values.

public mixed PARAM_INT_ARRAY = \Doctrine\DBAL\ArrayParameterType::INTEGER

PARAM_LOB

Represents a SQL large object data type.

public mixed PARAM_LOB = \Doctrine\DBAL\ParameterType::LARGE_OBJECT

PARAM_NULL

Represents a SQL NULL data type.

public mixed PARAM_NULL = \Doctrine\DBAL\ParameterType::NULL

PARAM_STR

Represents a SQL CHAR, VARCHAR data type.

public mixed PARAM_STR = \Doctrine\DBAL\ParameterType::STRING

PARAM_STR_ARRAY

Represents an array of string values.

public mixed PARAM_STR_ARRAY = \Doctrine\DBAL\ArrayParameterType::STRING

Methods

__construct()

Initializes a new instance of the Connection class.

public __construct(array $params, Driver $driver[, Configuration|null $config = null ]) : mixed

Parameters

$params : array

The connection parameters.

$driver : Driver

The driver to use.

$config : Configuration|null = null

The configuration, optional.

bulkInsert()

Bulk inserts table rows with specified data.

public bulkInsert(string $tableName, array $data[, array $columns = [] ][, array $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

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

$columns : array = []

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

$types : array = []

Types of the inserted data.

Return values

int —

The number of affected rows.

count()

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

public count(string $item, string $tableName, array $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

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 $identifier = [] ][, array $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 = []

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

$types : array = []

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.

getPlatformServerVersion()

Returns the version of the current platform if applicable, containing the platform as prefix.

public getPlatformServerVersion() : 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.

Return values

string

insert()

Inserts a table row with specified data.

public insert(string $tableName, array $data[, array $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

An associative array containing column-value pairs.

$types : array = []

Types of the inserted data.

Return values

int —

The number of affected rows.

lastInsertId()

Returns the ID of the last inserted row.

public lastInsertId() : numeric-string

If the underlying driver does not support identity columns, an exception is thrown.

Return values

numeric-string

prepareConnection()

Execute commands after initializing a new connection.

public prepareConnection(string $commands) : void

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 $input) : array

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

Parameters

$input : array

Return values

array

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.

Note that this does not call the parent implementation, because both Doctrine DBAL Connection::quoteIdentifier() and AbstractPlatform::quoteIdentifier() are deprecated and will be removed with Doctrine DBAL 5.0. The quoting is done here instead, identical to the removed implementation.

Parameters

$identifier : string

The name to be quoted.

Tags

not-deprecated

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 $input) : array

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

Parameters

$input : array

Return values

array

select()

Executes an SQL SELECT statement on a table.

public select(string[] $columns, string $tableName[, array $identifiers = [] ][, string[] $groupBy = [] ][, array $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 : string[]

The columns of the table which to select.

$tableName : string

The name of the table on which to select.

$identifiers : array = []

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

$groupBy : string[] = []

The columns to group the results by.

$orderBy : array = []

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.

transactional()

Executes a function in a transaction.

public transactional(callable(self): T $func) : T

The function gets passed this Connection instance as an (optional) parameter.

If an exception occurs during execution of the function or transaction commit, the transaction is rolled back and the exception re-thrown.

Parameters

$func : callable(self): T

The function to execute transactionally.

Tags

throws
Throwable
template

Return values

T —

The value returned by $func

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 $data[, array $identifier = [] ][, array $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

An associative array containing column-value pairs.

$identifier : array = []

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

$types : array = []

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

Return values

int —

The number of affected rows.

connect()

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

protected connect() : Connection

Return values

Connection

ensureDatabaseValueTypes()

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

protected ensureDatabaseValueTypes(string $tableName, array &$data, array &$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
$types : array

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 $input) : array

Parameters

$input : array

Return values

array

typo3_getServerVersionProvider()

Returns the suitable `ServerVersionProvider`, which could be the connection itself or a `StaticServerVersionProvider` based on either of following configuration values:

protected typo3_getServerVersionProvider() : ServerVersionProvider
  • $params['serverVersion']
  • $params['primary']['serverVersion']

This is an extract from Connection::getDatabasePlatform() and handled as internal for now and will be tried to provide upstream making it API and is the reason why it is a prefixed method.

It's currently only used in internal self::getPlatformServerVersion().

Return values

ServerVersionProvider
On this page