TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Connection Class Reference
Inheritance diagram for Connection:

Public Member Functions

 __construct (array $params, Driver $driver, Configuration $config=null, EventManager $em=null)
 
 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
 

Detailed Description

Definition at line 27 of file Connection.php.

Constructor & Destructor Documentation

__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
Doctrine

Definition at line 69 of file Connection.php.

References GeneralUtility\makeInstance().

Member Function Documentation

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

References GeneralUtility\makeInstance().

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

References Connection\createQueryBuilder().

createQueryBuilder ( )

Creates a new instance of a SQL query builder.

Returns

Definition at line 80 of file Connection.php.

References GeneralUtility\makeInstance().

Referenced by Connection\count(), OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), and Connection\select().

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

References Connection\quoteColumnValuePairs(), and Connection\quoteIdentifier().

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

Referenced by OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), and Typo3DatabaseBackend\isConnectionMysql().

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

References Connection\quoteColumnValuePairs(), and Connection\quoteIdentifier().

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 | null$fieldName
Returns
string

Definition at line 402 of file Connection.php.

prepareConnection ( string  $commands)

Execute commands after initializing a new connection.

Parameters
string$commands

Definition at line 365 of file Connection.php.

References GeneralUtility\SYSLOG_SEVERITY_ERROR, and GeneralUtility\trimExplode().

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

References Connection\quoteIdentifiers().

Referenced by Connection\delete(), Connection\insert(), and Connection\update().

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

Referenced by BulkInsertQuery\__construct(), Connection\delete(), Connection\insert(), ConnectionMigrator\transformTablesForDatabasePlatform(), Connection\truncate(), and Connection\update().

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

Referenced by Connection\quoteColumnValuePairs().

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

References Connection\createQueryBuilder().

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

References Connection\quoteIdentifier().

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

References Connection\quoteColumnValuePairs(), and Connection\quoteIdentifier().

Member Data Documentation

const PARAM_LOB = \PDO::PARAM_LOB

Represents a SQL large object data type.

Definition at line 47 of file Connection.php.

const PARAM_NULL = \PDO::PARAM_NULL

Represents a SQL NULL data type.

Definition at line 32 of file Connection.php.

const PARAM_STMT = \PDO::PARAM_STMT

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

Definition at line 52 of file Connection.php.