TYPO3 CMS  TYPO3_8-7
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)
 
 connect ()
 
 createQueryBuilder ()
 
 quoteIdentifier ($identifier)
 
 quoteIdentifiers (array $input)
 
 quoteColumnValuePairs (array $input)
 
 insert ($tableName, array $data, array $types=[])
 
 bulkInsert (string $tableName, array $data, array $columns=[], array $types=[])
 
 select (array $columns, string $tableName, array $identifiers=[], array $groupBy=[], array $orderBy=[], int $limit=0, int $offset=0)
 
 update ($tableName, array $data, array $identifier, array $types=[])
 
 delete ($tableName, array $identifier, array $types=[])
 
 truncate (string $tableName, bool $cascade=false)
 
 count (string $item, string $tableName, array $identifiers)
 
 getServerVersion ()
 
 prepareConnection (string $commands)
 
 lastInsertId ($tableName=null, string $fieldName='uid')
 

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

 quoteColumnTypes (array $input)
 

Private Attributes

 $prepareConnectionCommands = []
 

Detailed Description

Definition at line 27 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$paramsThe connection parameters.
Driver$driverThe driver to use.
Configuration | null$configThe configuration, optional.
EventManager | null$emThe event manager, optional.
Exceptions

Definition at line 74 of file Connection.php.

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

Member Function Documentation

◆ bulkInsert()

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. Table expression and columns are not escaped and are not safe for user-input.

Parameters
string$tableNameThe name of the table to insert data into.
array$dataAn array containing associative arrays of column-value pairs.
array$columnsAn array containing associative arrays of column-value pairs.
array$typesTypes of the inserted data.
Returns
int The number of affected rows.

Definition at line 215 of file Connection.php.

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

◆ connect()

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

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

Returns

Definition at line 85 of file Connection.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_ERROR.

◆ count()

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$itemThe column/expression of the table which to count
string$tableNameThe name of the table on which to count.
array$identifiersThe selection criteria. An associative array containing column-value pairs.
Returns
int The number of rows counted

Definition at line 348 of file Connection.php.

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

◆ createQueryBuilder()

◆ delete()

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. Table expression and columns are not escaped and are not safe for user-input.

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

Definition at line 309 of file Connection.php.

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

◆ getServerVersion()

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 370 of file Connection.php.

Referenced by TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), and TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend\isConnectionMysql().

◆ insert()

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. Table expression and columns are not escaped and are not safe for user-input.

Parameters
string$tableNameThe name of the table to insert data into.
array$dataAn associative array containing column-value pairs.
array$typesTypes of the inserted data.
Returns
int The number of affected rows.

Definition at line 193 of file Connection.php.

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

◆ lastInsertId()

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 439 of file Connection.php.

Referenced by TYPO3\CMS\Core\DataHandling\DataHandler\postProcessDatabaseInsert(), and TYPO3\CMS\Core\DataHandling\DataHandler\postProcessSqlServerInsert().

◆ prepareConnection()

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

Execute commands after initializing a new connection.

Parameters
string$commands

Definition at line 412 of file Connection.php.

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

◆ quoteColumnTypes()

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 172 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()

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 159 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(), and TYPO3\CMS\Core\Database\Connection\update().

◆ quoteIdentifier()

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$identifierThe name to be quoted.
Returns
string The quoted name.

Definition at line 126 of file Connection.php.

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

◆ quoteIdentifiers()

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 144 of file Connection.php.

Referenced by TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs().

◆ select()

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. Table expression and columns are not escaped and are not safe for user-input.

Parameters
string[]$columns The columns of the table which to select.
string$tableNameThe name of the table on which to select.
array$identifiersThe selection criteria. An associative array containing column-value pairs.
string[]$groupBy The columns to group the results by.
array$orderByAssociative array of column name/sort directions pairs.
int$limitThe maximum number of rows to return.
int$offsetThe first result row to select (when used with limit)
Returns
Statement The executed statement.

Definition at line 241 of file Connection.php.

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

◆ truncate()

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. Table expression is not escaped and not safe for user-input.

Parameters
string$tableNameThe name of the table to truncate.
bool$cascadeNot 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 theres no meaningful information.

Definition at line 329 of file Connection.php.

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

◆ update()

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. Table expression and columns are not escaped and are not safe for user-input.

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

Definition at line 287 of file Connection.php.

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

Member Data Documentation

◆ $prepareConnectionCommands

TYPO3\CMS\Core\Database\Connection::$prepareConnectionCommands = []
private

Definition at line 62 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 47 of file Connection.php.

Referenced by TYPO3\CMS\Scheduler\Scheduler\addTask(), TYPO3\CMS\Core\Database\QueryView\addToStoreQueryConfigs(), TYPO3\CMS\Core\Resource\Index\MetaDataRepository\createMetaDataRecord(), TYPO3\CMS\Impexp\Domain\Repository\PresetRepository\getPreset(), 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\Core\Tests\Functional\Category\Collection\CategoryCollectionTest\prepareTables(), 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\Core\Registry\set(), TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend\set(), TYPO3\CMS\Core\Tests\Functional\RegistryTest\setOverridesExistingEntryInDatabase(), TYPO3\CMS\IndexedSearch\Indexer\submitFilePage(), TYPO3\CMS\IndexedSearch\Indexer\submitPage(), TYPO3\CMS\Scheduler\Task\AbstractTask\unmarkAllExecutions(), TYPO3\CMS\Scheduler\Task\AbstractTask\unmarkExecution(), 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 32 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 52 of file Connection.php.

◆ PARAM_STR