‪TYPO3CMS  10.4
TYPO3\CMS\Core\Database\Connection Class Reference
Inheritance diagram for TYPO3\CMS\Core\Database\Connection:

Public Member Functions

 __construct (array $params, Driver $driver, Configuration $config=null, EventManager $em=null)
 
bool connect ()
 
TYPO3 CMS Core Database Query QueryBuilder createQueryBuilder ()
 
string quoteIdentifier ($identifier)
 
array quoteIdentifiers (array $input)
 
array quoteColumnValuePairs (array $input)
 
string escapeLikeWildcards (string $value)
 
int insert ($tableName, array $data, array $types=[])
 
int bulkInsert (string $tableName, array $data, array $columns=[], array $types=[])
 
Statement Doctrine DBAL ForwardCompatibility Result Doctrine DBAL Driver ResultStatement select (array $columns, string $tableName, array $identifiers=[], array $groupBy=[], array $orderBy=[], int $limit=0, int $offset=0)
 
int update ($tableName, array $data, array $identifier, array $types=[])
 
int delete ($tableName, array $identifier, array $types=[])
 
int truncate (string $tableName, bool $cascade=false)
 
int count (string $item, string $tableName, array $identifiers)
 
string getServerVersion ()
 
 prepareConnection (string $commands)
 
string lastInsertId ($tableName=null, string $fieldName='uid')
 
ExpressionBuilder getExpressionBuilder ()
 

Public Attributes

const PARAM_NULL = \PDO::PARAM_NULL
 
const PARAM_INT = \PDO::PARAM_INT
 
const PARAM_STR = \PDO::PARAM_STR
 
const PARAM_LOB = \PDO::PARAM_LOB
 
const PARAM_STMT = \PDO::PARAM_STMT
 
const PARAM_BOOL = \PDO::PARAM_BOOL
 

Protected Member Functions

array quoteColumnTypes (array $input)
 

Protected Attributes

ExpressionBuilder $_expr
 

Private Attributes

array $prepareConnectionCommands = array( )
 

Detailed Description

Definition at line 35 of file Connection.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Connection::__construct ( array  $params,
Driver  $driver,
Configuration  $config = null,
EventManager  $em = null 
)

Initializes a new instance of the Connection class.

Parameters
array$params‪The connection parameters.
Driver$driver‪The driver to use.
Configuration | null$config‪The configuration, optional.
EventManager | null$em‪The event manager, optional.
Exceptions

Definition at line 85 of file Connection.php.

Member Function Documentation

◆ bulkInsert()

int TYPO3\CMS\Core\Database\Connection::bulkInsert ( string  $tableName,
array  $data,
array  $columns = [],
array  $types = [] 
)

Bulk inserts table rows with specified data.

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

Parameters
string$tableName‪The name of the table to insert data into.
array$data‪An array containing associative arrays of column-value pairs or just the values to be inserted.
array$columns‪An array containing the column names of the data which should be inserted.
array$types‪Types of the inserted data.
Returns
‪int The number of affected rows.

Definition at line 232 of file Connection.php.

◆ connect()

bool TYPO3\CMS\Core\Database\Connection::connect ( )

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

Returns
‪bool

Definition at line 96 of file Connection.php.

◆ count()

int TYPO3\CMS\Core\Database\Connection::count ( string  $item,
string  $tableName,
array  $identifiers 
)

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

Parameters
string$item‪The column/expression of the table which to count
string$tableName‪The name of the table on which to count.
array$identifiers‪The selection criteria. An associative array containing column-value pairs.
Returns
‪int The number of rows counted

Definition at line 361 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\createQueryBuilder().

◆ createQueryBuilder()

◆ delete()

int TYPO3\CMS\Core\Database\Connection::delete (   $tableName,
array  $identifier,
array  $types = [] 
)

Executes an SQL DELETE statement on a table.

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

Parameters
string$tableName‪The name of the table on which to delete.
array$identifier‪The deletion criteria. An associative array containing column-value pairs.
array$types‪The types of identifiers.
Returns
‪int The number of affected rows.

Definition at line 323 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteColumnTypes(), TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs(), and TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

Referenced by TYPO3\CMS\Install\Updates\DatabaseRowsUpdateWizard\updateOrDeleteRow().

◆ escapeLikeWildcards()

string TYPO3\CMS\Core\Database\Connection::escapeLikeWildcards ( string  $value)

Quotes like wildcards for given string value.

Parameters
string$value‪The value to be quoted.
Returns
‪string The quoted value.

Definition at line 195 of file Connection.php.

◆ getExpressionBuilder()

ExpressionBuilder TYPO3\CMS\Core\Database\Connection::getExpressionBuilder ( )

Gets the ExpressionBuilder for the connection.

Returns
‪ExpressionBuilder

Definition at line 473 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\$_expr.

◆ getServerVersion()

string TYPO3\CMS\Core\Database\Connection::getServerVersion ( )

Returns the version of the current platform if applicable.

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.

Returns
‪string

Definition at line 383 of file Connection.php.

Referenced by TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\MySql\checkMysqlVersion(), TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\PostgreSql\checkPostgreSqlVersion(), TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), and TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend\isConnectionMysql().

◆ insert()

int TYPO3\CMS\Core\Database\Connection::insert (   $tableName,
array  $data,
array  $types = [] 
)

Inserts a table row with specified data.

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

Parameters
string$tableName‪The name of the table to insert data into.
array$data‪An associative array containing column-value pairs.
array$types‪Types of the inserted data.
Returns
‪int The number of affected rows.

Definition at line 211 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteColumnTypes(), TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs(), and TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

Referenced by TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\addRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\deleteRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\modifyRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\moveRecord(), TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend\set(), and TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\undeleteRecord().

◆ lastInsertId()

string TYPO3\CMS\Core\Database\Connection::lastInsertId (   $tableName = null,
string  $fieldName = 'uid' 
)

Returns the ID of the last inserted row or sequence value. 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
string | null$tableName
string$fieldName
Returns
‪string

Definition at line 452 of file Connection.php.

Referenced by TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\addRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\deleteRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\modifyRecord(), TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\moveRecord(), TYPO3\CMS\Core\DataHandling\DataHandler\postProcessDatabaseInsert(), TYPO3\CMS\Core\DataHandling\DataHandler\postProcessSqlServerInsert(), and TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\undeleteRecord().

◆ prepareConnection()

TYPO3\CMS\Core\Database\Connection::prepareConnection ( string  $commands)

Execute commands after initializing a new connection.

Parameters
string$commands

Definition at line 425 of file Connection.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ quoteColumnTypes()

array TYPO3\CMS\Core\Database\Connection::quoteColumnTypes ( array  $input)
protected

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

Parameters
array$input
Returns
‪array

Definition at line 179 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs().

Referenced by TYPO3\CMS\Core\Database\Connection\delete(), TYPO3\CMS\Core\Database\Connection\insert(), and TYPO3\CMS\Core\Database\Connection\update().

◆ quoteColumnValuePairs()

array TYPO3\CMS\Core\Database\Connection::quoteColumnValuePairs ( array  $input)

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

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

Parameters
array$input
Returns
‪array

Definition at line 166 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteIdentifiers().

Referenced by TYPO3\CMS\Core\Database\Connection\delete(), TYPO3\CMS\Core\Database\Connection\insert(), TYPO3\CMS\Core\Database\Connection\quoteColumnTypes(), TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteColumnValuePairs(), and TYPO3\CMS\Core\Database\Connection\update().

◆ quoteIdentifier()

string TYPO3\CMS\Core\Database\Connection::quoteIdentifier (   $identifier)

Quotes a string so it can be safely used as a table or column name, even if it is a reserved name. EXAMPLE: tableName.fieldName => "tableName"."fieldName"

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

Parameters
string$identifier‪The name to be quoted.
Returns
‪string The quoted name.

Definition at line 133 of file Connection.php.

Referenced by TYPO3\CMS\Core\Database\Query\BulkInsertQuery\__construct(), TYPO3\CMS\Core\Database\Connection\delete(), TYPO3\CMS\Core\Database\Query\BulkInsertQuery\getSQL(), TYPO3\CMS\Core\Database\Connection\insert(), TYPO3\CMS\Core\DataHandling\DataHandler\postProcessSqlServerInsert(), TYPO3\CMS\Core\Database\Query\QueryHelper\quoteDatabaseIdentifiers(), TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), TYPO3\CMS\Core\Database\Schema\ConnectionMigrator\transformTablesForDatabasePlatform(), TYPO3\CMS\Core\Database\Connection\truncate(), and TYPO3\CMS\Core\Database\Connection\update().

◆ quoteIdentifiers()

array TYPO3\CMS\Core\Database\Connection::quoteIdentifiers ( array  $input)

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

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

Parameters
array$input
Returns
‪array

Definition at line 151 of file Connection.php.

Referenced by TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifiers().

◆ select()

Statement Doctrine DBAL ForwardCompatibility Result Doctrine DBAL Driver ResultStatement TYPO3\CMS\Core\Database\Connection::select ( array  $columns,
string  $tableName,
array  $identifiers = [],
array  $groupBy = [],
array  $orderBy = [],
int  $limit = 0,
int  $offset = 0 
)

Executes an SQL SELECT statement on a table.

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

Parameters
string[]$columns‪The columns of the table which to select.
string$tableName‪The name of the table on which to select.
array$identifiers‪The selection criteria. An associative array containing column-value pairs.
string[]$groupBy‪The columns to group the results by.
array$orderBy‪Associative array of column name/sort directions pairs.
int$limit‪The maximum number of rows to return.
int$offset‪The first result row to select (when used with limit)
Returns
‪Statement|\Doctrine\DBAL\ForwardCompatibility\Result|\Doctrine\DBAL\Driver\ResultStatement The executed statement.

Definition at line 257 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\createQueryBuilder().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\count().

◆ truncate()

int TYPO3\CMS\Core\Database\Connection::truncate ( string  $tableName,
bool  $cascade = false 
)

Executes an SQL TRUNCATE statement on a table.

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

Parameters
string$tableName‪The name of the table to truncate.
bool$cascade‪Not supported on many platforms but would cascade the truncate by following foreign keys.
Returns
‪int The number of affected rows. For a truncate this is unreliable as there is no meaningful information.

Definition at line 342 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

◆ update()

int TYPO3\CMS\Core\Database\Connection::update (   $tableName,
array  $data,
array  $identifier,
array  $types = [] 
)

Executes an SQL UPDATE statement on a table.

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

Parameters
string$tableName‪The name of the table to update.
array$data‪An associative array containing column-value pairs.
array$identifier‪The update criteria. An associative array containing column-value pairs.
array$types‪Types of the merged $data and $identifier arrays in that order.
Returns
‪int The number of affected rows.

Definition at line 302 of file Connection.php.

References TYPO3\CMS\Core\Database\Connection\quoteColumnTypes(), TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs(), and TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

Referenced by TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\keepHistoryForInsertAndDeleteActions(), TYPO3\CMS\Core\Session\Backend\DatabaseSessionBackend\update(), TYPO3\CMS\Install\Updates\DatabaseRowsUpdateWizard\updateOrDeleteRow(), TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\updateTablesAndTrackProgress(), and TYPO3\CMS\Core\Database\RelationHandler\writeForeignField().

Member Data Documentation

◆ $_expr

ExpressionBuilder TYPO3\CMS\Core\Database\Connection::$_expr
protected

◆ $prepareConnectionCommands

array TYPO3\CMS\Core\Database\Connection::$prepareConnectionCommands = array( )
private

Definition at line 73 of file Connection.php.

◆ PARAM_BOOL

◆ PARAM_INT

◆ PARAM_LOB

const TYPO3\CMS\Core\Database\Connection::PARAM_LOB = \PDO::PARAM_LOB

Represents a SQL large object data type.

Definition at line 57 of file Connection.php.

Referenced by TYPO3\CMS\Core\Resource\ProcessedFileRepository\add(), TYPO3\CMS\Scheduler\Scheduler\addTask(), TYPO3\CMS\Core\Resource\Index\MetaDataRepository\createMetaDataRecord(), TYPO3\CMS\Install\Controller\InstallerController\executeDefaultConfigurationAction(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsEmptyStringUnzipped(), TYPO3\CMS\Core\Tests\Functional\RegistryTest\getReturnsEntryFromDatabase(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsFalseForExpiredCacheEntry(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsNotExpiredCacheEntry(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsUnzipsNotExpiredCacheEntry(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\hasReturnsFalseForExpiredCacheEntry(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\hasReturnsNotExpiredCacheEntry(), TYPO3\CMS\Core\DataHandling\DataHandler\insertDB(), TYPO3\CMS\Core\Tests\Unit\Database\ConnectionTest\insertQueriesDataProvider(), TYPO3\CMS\Scheduler\Task\AbstractTask\markExecution(), TYPO3\CMS\Impexp\Domain\Repository\PresetRepository\processPresets(), TYPO3\CMS\Core\Tests\Functional\RegistryTest\removeAllByNamespaceDeletesEntryInDatabaseAndLeavesOthers(), TYPO3\CMS\Core\Tests\Functional\RegistryTest\removeDeletesEntryInDatabaseButLeavesOthers(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\removeRemovesCorrectEntriesFromDatabase(), TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\removeReturnsTrueIfAnEntryHasBeenRemoved(), TYPO3\CMS\Extensionmanager\Controller\ListController\saveBackendUserFilter(), TYPO3\CMS\Core\Database\QueryView\saveQueryInAction(), TYPO3\CMS\Core\Registry\set(), TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend\set(), TYPO3\CMS\Core\Tests\Functional\RegistryTest\setOverridesExistingEntryInDatabase(), TYPO3\CMS\Scheduler\Task\AbstractTask\unmarkAllExecutions(), TYPO3\CMS\Scheduler\Task\AbstractTask\unmarkExecution(), TYPO3\CMS\Core\Resource\ProcessedFileRepository\update(), TYPO3\CMS\Core\Tests\Unit\Database\ConnectionTest\updateQueriesDataProvider(), TYPO3\CMS\IndexedSearch\Controller\SearchController\writeSearchStat(), and TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\writeUC().

◆ PARAM_NULL

const TYPO3\CMS\Core\Database\Connection::PARAM_NULL = \PDO::PARAM_NULL

Represents a SQL NULL data type.

Definition at line 42 of file Connection.php.

◆ PARAM_STMT

const TYPO3\CMS\Core\Database\Connection::PARAM_STMT = \PDO::PARAM_STMT

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

Definition at line 62 of file Connection.php.

◆ PARAM_STR