TYPO3 CMS  TYPO3_8-7
TYPO3\CMS\Core\Database\DatabaseConnection Class Reference

Public Member Functions

 initialize ()
 
 exec_SELECT_mm_query ($select, $local_table, $mm_table, $foreign_table, $whereClause='', $groupBy='', $orderBy='', $limit='')
 
 exec_SELECT_queryArray ($queryParts)
 
 exec_SELECTgetRows ($select_fields, $from_table, $where_clause, $groupBy='', $orderBy='', $limit='', $uidIndexField='')
 
 exec_SELECTgetSingleRow ($select_fields, $from_table, $where_clause, $groupBy='', $orderBy='', $numIndex=false)
 
 exec_SELECTcountRows ($field, $table, $where='1=1')
 
 INSERTquery ($table, $fields_values, $no_quote_fields=false)
 
 SELECTsubquery ($select_fields, $from_table, $where_clause)
 
 SELECT_mm_query ($select, $local_table, $mm_table, $foreign_table, $whereClause='', $groupBy='', $orderBy='', $limit='')
 
 listQuery ($field, $value, $table)
 
 searchQuery ($searchWords, $fields, $table, $constraint=self::AND_Constraint)
 
 prepare_SELECTqueryArray (array $queryParts, array $input_parameters=[])
 
 prepare_PREPAREDquery ($query, array $queryComponents)
 
 fullQuoteStr ($str, $table, $allowNull=false)
 
 fullQuoteArray ($arr, $table, $noQuote=false, $allowNull=false)
 
 quoteStr ($str, $table)
 
 escapeStrForLike ($str, $table)
 
 cleanIntArray ($arr)
 
 cleanIntList ($list)
 
 stripOrderBy ($str)
 
 stripGroupBy ($str)
 
 getDateTimeFormats ($table)
 
 sql_query ($query)
 
 sql_error ()
 
 sql_errno ()
 
 sql_num_rows ($res)
 
 sql_fetch_assoc ($res)
 
 sql_fetch_row ($res)
 
 sql_free_result ($res)
 
 sql_insert_id ()
 
 sql_affected_rows ()
 
 sql_data_seek ($res, $seek)
 
 sql_field_type ($res, $pointer)
 
 sql_select_db ()
 
 admin_get_dbs ()
 
 admin_get_tables ()
 
 admin_get_fields ($tableName)
 
 admin_get_keys ($tableName)
 
 admin_get_charsets ()
 
 admin_query ($query)
 
 setDatabaseHost ($host='localhost')
 
 setDatabasePort ($port=3306)
 
 setDatabaseSocket ($socket=null)
 
 setDatabaseName ($name)
 
 setDatabaseUsername ($username)
 
 setDatabasePassword ($password)
 
 setPersistentDatabaseConnection ($persistentDatabaseConnection)
 
 setConnectionCompression ($connectionCompression)
 
 setInitializeCommandsAfterConnect (array $commands)
 
 setConnectionCharset ($connectionCharset='utf8')
 
 connectDB ()
 
 isConnected ()
 
 getDatabaseHandle ()
 
 setDatabaseHandle ($handle)
 
 getServerVersion ()
 
 debug ($func, $query='')
 
 debug_check_recordset ($res)
 
 __sleep ()
 

Public Attributes

const AND_Constraint = 'AND'
 
const OR_Constraint = 'OR'
 
 $debugOutput = false
 
 $debug_lastBuiltQuery = ''
 
 $store_lastBuiltQuery = false
 
 $explainOutput = 0
 
 $default_charset = 'utf8'
 

Protected Member Functions

 query ($query)
 
 getSelectMmQueryParts ($select, $local_table, $mm_table, $foreign_table, $whereClause='', $groupBy='', $orderBy='', $limit='')
 
 checkConnectionCharset ()
 
 disconnectIfConnected ()
 
 logDeprecation ()
 

Protected Attributes

 $databaseHost = ''
 
 $databasePort = 3306
 
 $databaseSocket = null
 
 $databaseName = ''
 
 $databaseUsername = ''
 
 $databaseUserPassword = ''
 
 $persistentDatabaseConnection = false
 
 $connectionCompression = false
 
 $connectionCharset = 'utf8'
 
 $initializeCommandsAfterConnect = []
 
 $isConnected = false
 
 $link = null
 
 $preProcessHookObjects = []
 
 $postProcessHookObjects = []
 
 $deprecationWarningThrown = false
 

Detailed Description

Deprecated:
----------— THE WHOLE CLASS WILL BE REMOVED IN TYPO3 v9 -------------------------------------------—

TYPO3 "database wrapper" class (new in 3.6.0) This class contains

  • abstraction functions for executing INSERT/UPDATE/DELETE/SELECT queries ("Query execution"; These are REQUIRED for all future connectivity to the database, thus ensuring DBAL compliance!)
  • functions for building SQL queries (INSERT/UPDATE/DELETE/SELECT) ("Query building"); These are transitional functions for building SQL queries in a more automated way. Use these to build queries instead of doing it manually in your code!
  • mysqli wrapper functions; These are transitional functions. By a simple search/replace you should be able to substitute all mysql*() calls with $GLOBALS['TYPO3_DB']->sql*() and your application will work out of the box. YOU CANNOT (legally) use any mysqli functions not found as wrapper functions in this class! See the Project Coding Guidelines (doc_core_cgl) for more instructions on best-practise

This class is not in itself a complete database abstraction layer but can be extended to be a DBAL (by extensions, see "dbal" for example) ALL connectivity to the database in TYPO3 must be done through this class! The points of this class are:

  • To direct all database calls through this class so it becomes possible to implement DBAL with extensions.
  • To keep it very easy to use for developers used to MySQL in PHP - and preserve as much performance as possible when TYPO3 is used with MySQL directly...
  • To create an interface for DBAL implemented by extensions; (Eg. making possible escaping characters, clob/blob handling, reserved words handling)
  • Benchmarking the DB bottleneck queries will become much easier; Will make it easier to find optimization possibilities.

USE: In all TYPO3 scripts the global variable $TYPO3_DB is an instance of this class. Use that. Eg. $GLOBALS['TYPO3_DB']->sql_fetch_assoc()

Definition at line 50 of file DatabaseConnection.php.

Member Function Documentation

◆ __sleep()

TYPO3\CMS\Core\Database\DatabaseConnection::__sleep ( )

Serialize destructs current connection

Returns
array All protected properties that should be saved

Definition at line 1982 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ admin_get_charsets()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_get_charsets ( )

Returns information about the character sets supported by the current DBM This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery.

This is used by the Install Tool to convert tables with non-UTF8 charsets Use in Install Tool only!

Returns
array Array with Charset as key and an array of "Charset", "Description", "Default collation", "Maxlen" as values

Definition at line 1473 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

◆ admin_get_dbs()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_get_dbs ( )

Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database. This is only used as a service function in the (1-2-3 process) of the Install Tool. In any case a lookup should be done in the _DEFAULT handler DBMS then. Use in Install Tool only!

Returns
array Each entry represents a database name
Exceptions

Definition at line 1367 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), TYPO3\CMS\Core\Database\DatabaseConnection\query(), TYPO3\CMS\Core\Database\DatabaseConnection\setDatabaseName(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_error(), and TYPO3\CMS\Core\Database\DatabaseConnection\sql_select_db().

◆ admin_get_fields()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_get_fields (   $tableName)

Returns information about each field in the $table (quering the DBMS) In a DBAL this should look up the right handler for the table and return compatible information This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery.

Parameters
string$tableNameTable name
Returns
array Field information in an associative array with fieldname => field row

Definition at line 1426 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

◆ admin_get_keys()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_get_keys (   $tableName)

Returns information about each index key in the $table (quering the DBMS) In a DBAL this should look up the right handler for the table and return compatible information

Parameters
string$tableNameTable name
Returns
array Key information in a numeric array

Definition at line 1447 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

◆ admin_get_tables()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_get_tables ( )

Returns the list of tables from the default database, TYPO3_db (quering the DBMS) In a DBAL this method should 1) look up all tables from the DBMS of the _DEFAULT handler and then 2) add all tables configured to be managed by other handlers

Returns
array Array with tablenames as key and arrays with status information as value

Definition at line 1401 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

◆ admin_query()

TYPO3\CMS\Core\Database\DatabaseConnection::admin_query (   $query)

mysqli() wrapper function, used by the Install Tool and EM for all queries regarding management of the database!

Parameters
string$queryQuery to execute
Returns
bool||object MySQLi result object / DBAL object

Definition at line 1493 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug(), TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

◆ checkConnectionCharset()

TYPO3\CMS\Core\Database\DatabaseConnection::checkConnectionCharset ( )
protected

Checks if the current connection character set has the same value as the connectionCharset variable.

To determine the character set these MySQL session variables are checked: character_set_client, character_set_results and character_set_connection.

If the character set does not match or if the session variables can not be read a RuntimeException is thrown.

Exceptions

Definition at line 1712 of file DatabaseConnection.php.

References $GLOBALS, TYPO3\CMS\Core\Database\DatabaseConnection\sql_error(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_row(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_free_result(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_query(), and TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_ERROR.

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\sql_field_type().

◆ cleanIntArray()

TYPO3\CMS\Core\Database\DatabaseConnection::cleanIntArray (   $arr)

Will convert all values in the one-dimensional array to integers. Useful when you want to make sure an array contains only integers before imploding them in a select-list.

Parameters
array$arrArray with values
Returns
array The input array with all values cast to (int)
See also
cleanIntList()

Definition at line 957 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ cleanIntList()

TYPO3\CMS\Core\Database\DatabaseConnection::cleanIntList (   $list)

Will force all entries in the input comma list to integers Useful when you want to make sure a commalist of supposed integers really contain only integers; You want to know that when you don't trust content that could go into an SQL statement.

Parameters
string$listList of comma-separated values which should be integers
Returns
string The input list but with every value cast to (int)
See also
cleanIntArray()

Definition at line 971 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\intExplode(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ connectDB()

◆ debug()

◆ debug_check_recordset()

◆ disconnectIfConnected()

◆ escapeStrForLike()

TYPO3\CMS\Core\Database\DatabaseConnection::escapeStrForLike (   $str,
  $table 
)

Escaping values for SQL LIKE statements.

Parameters
string$strInput string
string$tableTable name for which to escape string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!).
Returns
string Output string; % and _ will be escaped with \ (or otherwise based on DBAL handler)
See also
quoteStr()

Definition at line 943 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ exec_SELECT_mm_query()

TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECT_mm_query (   $select,
  $local_table,
  $mm_table,
  $foreign_table,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)

Creates and executes a SELECT query, selecting fields ($select) from two/three tables joined Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. The JOIN is done with [$local_table].uid <–> [$mm_table].uid_local / [$mm_table].uid_foreign <–> [$foreign_table].uid The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details.

Parameters
string$selectField list for SELECT
string$local_tableTablename, local table
string$mm_tableTablename, relation table
string$foreign_tableTablename, foreign table
string$whereClauseOptional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! You have to prepend 'AND ' to this parameter yourself!
string$groupByOptional GROUP BY field(s), if none, supply blank string.
string$orderByOptional ORDER BY field(s), if none, supply blank string.
string$limitOptional LIMIT value ([begin,]max), if none, supply blank string.
Returns
bool||object MySQLi result object / DBAL object
See also
exec_SELECTquery()

Definition at line 342 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECT_queryArray(), TYPO3\CMS\Core\Database\DatabaseConnection\getSelectMmQueryParts(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ exec_SELECT_queryArray()

TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECT_queryArray (   $queryParts)

Executes a select based on input query parts array

Parameters
array$queryPartsQuery parts array
Returns
bool||object MySQLi result object / DBAL object
See also
exec_SELECTquery()

Definition at line 356 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECT_mm_query().

◆ exec_SELECTcountRows()

TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECTcountRows (   $field,
  $table,
  $where = '1=1' 
)

Counts the number of rows in a table.

Parameters
string$fieldName of the field to use in the COUNT() expression (e.g. '*')
string$tableName of the table to count rows for
string$where(optional) WHERE statement of the query
Returns
mixed Number of rows counter (int) or FALSE if something went wrong (bool)

Definition at line 440 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug(), TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), TYPO3\CMS\Core\Database\DatabaseConnection\query(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_row(), and TYPO3\CMS\Core\Database\DatabaseConnection\sql_free_result().

◆ exec_SELECTgetRows()

TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECTgetRows (   $select_fields,
  $from_table,
  $where_clause,
  $groupBy = '',
  $orderBy = '',
  $limit = '',
  $uidIndexField = '' 
)

Creates and executes a SELECT SQL-statement AND traverse result set and returns array with records in.

Parameters
string$select_fieldsList of fields to select from the table. This is what comes right after "SELECT ...". Required value.
string$from_tableTable(s) from which to select. This is what comes right after "FROM ...". Required value.
string$where_clauseAdditional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
string$groupByOptional GROUP BY field(s), if none, supply blank string.
string$orderByOptional ORDER BY field(s), if none, supply blank string.
string$limitOptional LIMIT value ([begin,]max), if none, supply blank string.
string$uidIndexFieldIf set, the result array will carry this field names value as index. Requires that field to be selected of course!
Returns
array|null Array of rows, or NULL in case of SQL error
See also
exec_SELECTquery()
Exceptions

Definition at line 376 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_error(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_assoc(), and TYPO3\CMS\Core\Database\DatabaseConnection\sql_free_result().

◆ exec_SELECTgetSingleRow()

TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECTgetSingleRow (   $select_fields,
  $from_table,
  $where_clause,
  $groupBy = '',
  $orderBy = '',
  $numIndex = false 
)

Creates and executes a SELECT SQL-statement AND gets a result set and returns an array with a single record in. LIMIT is automatically set to 1 and can not be overridden.

Parameters
string$select_fieldsList of fields to select from the table.
string$from_tableTable(s) from which to select.
string$where_clauseOptional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
string$groupByOptional GROUP BY field(s), if none, supply blank string.
string$orderByOptional ORDER BY field(s), if none, supply blank string.
bool$numIndexIf set, the result will be fetched with sql_fetch_row, otherwise sql_fetch_assoc will be used.
Returns
array|false|null Single row, FALSE on empty result, NULL on error

Definition at line 416 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_assoc(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_row(), and TYPO3\CMS\Core\Database\DatabaseConnection\sql_free_result().

◆ fullQuoteArray()

TYPO3\CMS\Core\Database\DatabaseConnection::fullQuoteArray (   $arr,
  $table,
  $noQuote = false,
  $allowNull = false 
)

Will fullquote all values in the one-dimensional array so they are ready to "implode" for an sql query.

Parameters
array$arrArray with values (either associative or non-associative array)
string$tableTable name for which to quote
bool | array | string$noQuoteList/array of keys NOT to quote (eg. SQL functions) - ONLY for associative arrays
bool$allowNullWhether to allow NULL values
Returns
array The input array with the values quoted
See also
cleanIntArray()

Definition at line 897 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\fullQuoteStr(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\INSERTquery().

◆ fullQuoteStr()

TYPO3\CMS\Core\Database\DatabaseConnection::fullQuoteStr (   $str,
  $table,
  $allowNull = false 
)

Escaping and quoting values for SQL statements.

Parameters
string$strInput string
string$tableTable name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!).
bool$allowNullWhether to allow NULL values
Returns
string Output string; Wrapped in single quotes and quotes in the string (" / ') and \ will be backslashed (or otherwise based on DBAL handler)
See also
quoteStr()

Definition at line 871 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\connectDB(), TYPO3\CMS\Core\Database\DatabaseConnection\isConnected(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\fullQuoteArray().

◆ getDatabaseHandle()

TYPO3\CMS\Core\Database\DatabaseConnection::getDatabaseHandle ( )

Returns current database handle

Returns
|null

Definition at line 1791 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\$link, and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ getDateTimeFormats()

TYPO3\CMS\Core\Database\DatabaseConnection::getDateTimeFormats (   $table)

Returns the date and time formats compatible with the given database table.

Parameters
string$tableTable name for which to return an empty date. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how date and time should be formatted).
Returns
array

Definition at line 1013 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\Query\QueryHelper\getDateTimeFormats(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ getSelectMmQueryParts()

TYPO3\CMS\Core\Database\DatabaseConnection::getSelectMmQueryParts (   $select,
  $local_table,
  $mm_table,
  $foreign_table,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)
protected

Creates SELECT query components for selecting fields ($select) from two/three tables joined Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. The JOIN is done with [$local_table].uid <–> [$mm_table].uid_local / [$mm_table].uid_foreign <–> [$foreign_table].uid The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details.

Parameters
string$selectSee exec_SELECT_mm_query()
string$local_tableSee exec_SELECT_mm_query()
string$mm_tableSee exec_SELECT_mm_query()
string$foreign_tableSee exec_SELECT_mm_query()
string$whereClauseSee exec_SELECT_mm_query()
string$groupBySee exec_SELECT_mm_query()
string$orderBySee exec_SELECT_mm_query()
string$limitSee exec_SELECT_mm_query()
Returns
array SQL query components

Definition at line 1035 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Utility\StringUtility\getUniqueId().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECT_mm_query(), and TYPO3\CMS\Core\Database\DatabaseConnection\SELECT_mm_query().

◆ getServerVersion()

TYPO3\CMS\Core\Database\DatabaseConnection::getServerVersion ( )

Get the MySQL server version

Returns
string

Definition at line 1812 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ initialize()

◆ INSERTquery()

TYPO3\CMS\Core\Database\DatabaseConnection::INSERTquery (   $table,
  $fields_values,
  $no_quote_fields = false 
)

Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.

Parameters
string$tableSee exec_INSERTquery()
array$fields_valuesSee exec_INSERTquery()
bool | array | string$no_quote_fieldsSee fullQuoteArray()
Returns
string|null Full SQL query for INSERT, NULL if $fields_values is empty

Definition at line 502 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\fullQuoteArray(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\initialize().

◆ isConnected()

◆ listQuery()

TYPO3\CMS\Core\Database\DatabaseConnection::listQuery (   $field,
  $value,
  $table 
)

Returns a WHERE clause that can find a value ($value) in a list field ($field) For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their position in the list (left, middle or right). The value must not contain a comma (,) Is nice to look up list-relations to records or files in TYPO3 database tables.

Parameters
string$fieldField name
string$valueValue to find in list
string$tableTable in which we are searching (for DBAL detection of quoteStr() method)
Returns
string WHERE clause for a query
Exceptions

Definition at line 744 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\quoteStr().

◆ logDeprecation()

TYPO3\CMS\Core\Database\DatabaseConnection::logDeprecation ( )
protected

function to call a deprecation log entry (but only once per request / class)

Definition at line 2004 of file DatabaseConnection.php.

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

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_charsets(), TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_dbs(), TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_fields(), TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_keys(), TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_tables(), TYPO3\CMS\Core\Database\DatabaseConnection\admin_query(), TYPO3\CMS\Core\Database\DatabaseConnection\cleanIntArray(), TYPO3\CMS\Core\Database\DatabaseConnection\cleanIntList(), TYPO3\CMS\Core\Database\DatabaseConnection\connectDB(), TYPO3\CMS\Core\Database\DatabaseConnection\debug(), TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), TYPO3\CMS\Core\Database\DatabaseConnection\escapeStrForLike(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECT_mm_query(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECT_queryArray(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTcountRows(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTgetRows(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTgetSingleRow(), TYPO3\CMS\Core\Database\DatabaseConnection\fullQuoteArray(), TYPO3\CMS\Core\Database\DatabaseConnection\fullQuoteStr(), TYPO3\CMS\Core\Database\DatabaseConnection\getDatabaseHandle(), TYPO3\CMS\Core\Database\DatabaseConnection\getDateTimeFormats(), TYPO3\CMS\Core\Database\DatabaseConnection\getServerVersion(), TYPO3\CMS\Core\Database\DatabaseConnection\initialize(), TYPO3\CMS\Core\Database\DatabaseConnection\INSERTquery(), TYPO3\CMS\Core\Database\DatabaseConnection\listQuery(), TYPO3\CMS\Core\Database\DatabaseConnection\prepare_PREPAREDquery(), TYPO3\CMS\Core\Database\DatabaseConnection\prepare_SELECTqueryArray(), TYPO3\CMS\Core\Database\DatabaseConnection\query(), TYPO3\CMS\Core\Database\DatabaseConnection\quoteStr(), TYPO3\CMS\Core\Database\DatabaseConnection\searchQuery(), TYPO3\CMS\Core\Database\DatabaseConnection\SELECT_mm_query(), TYPO3\CMS\Core\Database\DatabaseConnection\SELECTsubquery(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_data_seek(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_errno(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_error(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_assoc(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_fetch_row(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_free_result(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_insert_id(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_num_rows(), TYPO3\CMS\Core\Database\DatabaseConnection\sql_query(), TYPO3\CMS\Core\Database\DatabaseConnection\stripGroupBy(), and TYPO3\CMS\Core\Database\DatabaseConnection\stripOrderBy().

◆ prepare_PREPAREDquery()

TYPO3\CMS\Core\Database\DatabaseConnection::prepare_PREPAREDquery (   $query,
array  $queryComponents 
)

Prepares a prepared query.

Parameters
string$queryThe query to execute
array$queryComponentsThe components of the query to execute
Returns
|object MySQLi statement / DBAL object

Definition at line 838 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\connectDB(), TYPO3\CMS\Core\Database\DatabaseConnection\debug(), TYPO3\CMS\Core\Database\DatabaseConnection\isConnected(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ prepare_SELECTqueryArray()

TYPO3\CMS\Core\Database\DatabaseConnection::prepare_SELECTqueryArray ( array  $queryParts,
array  $input_parameters = [] 
)

Creates a SELECT prepared SQL statement based on input query parts array

Parameters
array$queryPartsQuery parts array
array$input_parametersAn array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as ::PARAM_AUTOTYPE.
Returns
Prepared statement

Definition at line 824 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ query()

◆ quoteStr()

TYPO3\CMS\Core\Database\DatabaseConnection::quoteStr (   $str,
  $table 
)

Substitution for PHP function "addslashes()" Use this function instead of the PHP addslashes() function when you build queries - this will prepare your code for DBAL. NOTICE: You must wrap the output of this function in SINGLE QUOTES to be DBAL compatible. Unless you have to apply the single quotes yourself you should rather use ->fullQuoteStr()!

Parameters
string$strInput string
string$tableTable name for which to quote string. Just enter the table that the field-value is selected from (and any DBAL will look up which handler to use and then how to quote the string!).
Returns
string Output string; Quotes (" / ') and \ will be backslashed (or otherwise based on DBAL handler)
See also
quoteStr()

Definition at line 926 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\connectDB(), TYPO3\CMS\Core\Database\DatabaseConnection\isConnected(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\listQuery().

◆ searchQuery()

TYPO3\CMS\Core\Database\DatabaseConnection::searchQuery (   $searchWords,
  $fields,
  $table,
  $constraint = self::AND_Constraint 
)

Returns a WHERE clause which will make an AND or OR search for the words in the $searchWords array in any of the fields in array $fields.

Parameters
array$searchWordsArray of search words
array$fieldsArray of fields
string$tableTable in which we are searching (for DBAL detection of quoteStr() method)
string$constraintHow multiple search words have to match ('AND' or 'OR')
Returns
string WHERE clause for search

Definition at line 765 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance(), and TYPO3\CMS\Core\Database\PreparedStatement\PARAM_AUTOTYPE.

◆ SELECT_mm_query()

TYPO3\CMS\Core\Database\DatabaseConnection::SELECT_mm_query (   $select,
  $local_table,
  $mm_table,
  $foreign_table,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)

Creates a SELECT query, selecting fields ($select) from two/three tables joined Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation. The JOIN is done with [$local_table].uid <–> [$mm_table].uid_local / [$mm_table].uid_foreign <–> [$foreign_table].uid The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $GLOBALS['TCA'] in Inside TYPO3 for more details.

Parameters
string$selectSee exec_SELECT_mm_query()
string$local_tableSee exec_SELECT_mm_query()
string$mm_tableSee exec_SELECT_mm_query()
string$foreign_tableSee exec_SELECT_mm_query()
string$whereClauseSee exec_SELECT_mm_query()
string$groupBySee exec_SELECT_mm_query()
string$orderBySee exec_SELECT_mm_query()
string$limitSee exec_SELECT_mm_query()
Returns
string Full SQL query for SELECT
See also
SELECTquery()

Definition at line 699 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\getSelectMmQueryParts(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ SELECTsubquery()

TYPO3\CMS\Core\Database\DatabaseConnection::SELECTsubquery (   $select_fields,
  $from_table,
  $where_clause 
)

Creates a SELECT SQL-statement to be used as subquery within another query. BEWARE: This method should not be overridden within DBAL to prevent quoting from happening.

Parameters
string$select_fieldsList of fields to select from the table.
string$from_tableTable from which to select.
string$where_clauseConditional WHERE statement
Returns
string Full SQL query for SELECT

Definition at line 669 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ setConnectionCharset()

TYPO3\CMS\Core\Database\DatabaseConnection::setConnectionCharset (   $connectionCharset = 'utf8')

Set the charset that should be used for the MySQL connection. The given value will be passed on to mysqli_set_charset().

The default value of this setting is utf8.

Parameters
string$connectionCharsetThe connection charset that will be passed on to mysqli_set_charset() when connecting the database. Default is utf8.

Definition at line 1617 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\$connectionCharset, and TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setConnectionCompression()

TYPO3\CMS\Core\Database\DatabaseConnection::setConnectionCompression (   $connectionCompression)

Set connection compression. Might be an advantage, if SQL server is not on localhost

Parameters
bool$connectionCompressionTRUE if connection should be compressed

Definition at line 1592 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\$connectionCompression, and TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setDatabaseHandle()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabaseHandle (   $handle)

Set current database handle, usually

Parameters
\mysqli$handle

Definition at line 1802 of file DatabaseConnection.php.

◆ setDatabaseHost()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabaseHost (   $host = 'localhost')

Set database host

Parameters
string$host

Definition at line 1514 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setDatabaseName()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabaseName (   $name)

Set database name

Parameters
string$name

Definition at line 1547 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\admin_get_dbs().

◆ setDatabasePassword()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabasePassword (   $password)

Set database password

Parameters
string$password

Definition at line 1569 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setDatabasePort()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabasePort (   $port = 3306)

Set database port

Parameters
int$port

Definition at line 1525 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setDatabaseSocket()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabaseSocket (   $socket = null)

Set database socket

Parameters
string | null$socket

Definition at line 1536 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setDatabaseUsername()

TYPO3\CMS\Core\Database\DatabaseConnection::setDatabaseUsername (   $username)

Set database username

Parameters
string$username

Definition at line 1558 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setInitializeCommandsAfterConnect()

TYPO3\CMS\Core\Database\DatabaseConnection::setInitializeCommandsAfterConnect ( array  $commands)

Set commands to be fired after connection was established

Parameters
array$commandsList of SQL commands to be executed after connect

Definition at line 1603 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\disconnectIfConnected().

◆ setPersistentDatabaseConnection()

TYPO3\CMS\Core\Database\DatabaseConnection::setPersistentDatabaseConnection (   $persistentDatabaseConnection)

◆ sql_affected_rows()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_affected_rows ( )

Returns the number of rows affected by the last INSERT, UPDATE or DELETE query

Returns
int Number of rows affected by last query

Definition at line 1193 of file DatabaseConnection.php.

◆ sql_data_seek()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_data_seek (   $res,
  $seek 
)

Move internal result pointer

Parameters
bool | \mysqli_result | object$resMySQLi result object / DBAL object
int$seekSeek result number.
Returns
bool Returns TRUE on success or FALSE on failure.

Definition at line 1205 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ sql_errno()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_errno ( )

Returns the error number on the last query() execution

Returns
int MySQLi error number

Definition at line 1096 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ sql_error()

◆ sql_fetch_assoc()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_fetch_assoc (   $res)

Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. MySQLi fetch_assoc() wrapper function

Parameters
bool | \mysqli_result | object$resMySQLi result object / DBAL object
Returns
array|bool Associative array of result row.

Definition at line 1124 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTgetRows(), and TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTgetSingleRow().

◆ sql_fetch_row()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_fetch_row (   $res)

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. The array contains the values in numerical indices. MySQLi fetch_row() wrapper function

Parameters
bool | \mysqli_result | object$resMySQLi result object / DBAL object
Returns
array|bool Array with result rows.

Definition at line 1146 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\checkConnectionCharset(), TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTcountRows(), and TYPO3\CMS\Core\Database\DatabaseConnection\exec_SELECTgetSingleRow().

◆ sql_field_type()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_field_type (   $res,
  $pointer 
)

◆ sql_free_result()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_free_result (   $res)

◆ sql_insert_id()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_insert_id ( )

Get the ID generated from the previous INSERT operation

Returns
int The uid of the last inserted record.

Definition at line 1182 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ sql_num_rows()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_num_rows (   $res)

Returns the number of selected rows.

Parameters
bool | \mysqli_result | object$resMySQLi result object / DBAL object
Returns
int Number of resulting rows

Definition at line 1108 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset(), and TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset().

◆ sql_query()

TYPO3\CMS\Core\Database\DatabaseConnection::sql_query (   $query)

Executes query MySQLi query() wrapper function Beware: Use of this method should be avoided as it is experimentally supported by DBAL. You should consider using exec_SELECTquery() and similar methods instead.

Parameters
string$queryQuery to execute
Returns
bool||object MySQLi result object / DBAL object

Definition at line 1070 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\debug(), TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation(), and TYPO3\CMS\Core\Database\DatabaseConnection\query().

Referenced by TYPO3\CMS\Core\Database\DatabaseConnection\checkConnectionCharset(), and TYPO3\CMS\Core\Database\DatabaseConnection\debug_check_recordset().

◆ sql_select_db()

◆ stripGroupBy()

TYPO3\CMS\Core\Database\DatabaseConnection::stripGroupBy (   $str)

Removes the prefix "GROUP BY" from the input string. This function is used when you call the SELECTquery() function and want to pass the GROUP BY parameter by can't guarantee that "GROUP BY" is not prefixed. Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result.

Parameters
string$streg. "GROUP BY title, uid @return string eg. "title, uid
See also
exec_SELECTquery(), stripOrderBy()

Definition at line 1001 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

◆ stripOrderBy()

TYPO3\CMS\Core\Database\DatabaseConnection::stripOrderBy (   $str)

Removes the prefix "ORDER BY" from the input string. This function is used when you call the exec_SELECTquery() function and want to pass the ORDER BY parameter by can't guarantee that "ORDER BY" is not prefixed. Generally; This function provides a work-around to the situation where you cannot pass only the fields by which to order the result.

Parameters
string$streg. "ORDER BY title, uid @return string eg. "title, uid
See also
exec_SELECTquery(), stripGroupBy()

Definition at line 986 of file DatabaseConnection.php.

References TYPO3\CMS\Core\Database\DatabaseConnection\logDeprecation().

Member Data Documentation

◆ $connectionCharset

TYPO3\CMS\Core\Database\DatabaseConnection::$connectionCharset = 'utf8'
protected

◆ $connectionCompression

TYPO3\CMS\Core\Database\DatabaseConnection::$connectionCompression = false
protected

◆ $databaseHost

TYPO3\CMS\Core\Database\DatabaseConnection::$databaseHost = ''
protected

◆ $databaseName

TYPO3\CMS\Core\Database\DatabaseConnection::$databaseName = ''
protected

Definition at line 113 of file DatabaseConnection.php.

◆ $databasePort

TYPO3\CMS\Core\Database\DatabaseConnection::$databasePort = 3306
protected

Definition at line 103 of file DatabaseConnection.php.

◆ $databaseSocket

TYPO3\CMS\Core\Database\DatabaseConnection::$databaseSocket = null
protected

Definition at line 108 of file DatabaseConnection.php.

◆ $databaseUsername

TYPO3\CMS\Core\Database\DatabaseConnection::$databaseUsername = ''
protected

Definition at line 118 of file DatabaseConnection.php.

◆ $databaseUserPassword

TYPO3\CMS\Core\Database\DatabaseConnection::$databaseUserPassword = ''
protected

Definition at line 123 of file DatabaseConnection.php.

◆ $debug_lastBuiltQuery

TYPO3\CMS\Core\Database\DatabaseConnection::$debug_lastBuiltQuery = ''

◆ $debugOutput

TYPO3\CMS\Core\Database\DatabaseConnection::$debugOutput = false

Definition at line 71 of file DatabaseConnection.php.

◆ $default_charset

TYPO3\CMS\Core\Database\DatabaseConnection::$default_charset = 'utf8'

Definition at line 164 of file DatabaseConnection.php.

◆ $deprecationWarningThrown

TYPO3\CMS\Core\Database\DatabaseConnection::$deprecationWarningThrown = false
protected

Definition at line 181 of file DatabaseConnection.php.

◆ $explainOutput

TYPO3\CMS\Core\Database\DatabaseConnection::$explainOutput = 0

Definition at line 93 of file DatabaseConnection.php.

◆ $initializeCommandsAfterConnect

TYPO3\CMS\Core\Database\DatabaseConnection::$initializeCommandsAfterConnect = []
protected

Definition at line 147 of file DatabaseConnection.php.

◆ $isConnected

TYPO3\CMS\Core\Database\DatabaseConnection::$isConnected = false
protected

◆ $link

TYPO3\CMS\Core\Database\DatabaseConnection::$link = null
protected

◆ $persistentDatabaseConnection

TYPO3\CMS\Core\Database\DatabaseConnection::$persistentDatabaseConnection = false
protected

◆ $postProcessHookObjects

TYPO3\CMS\Core\Database\DatabaseConnection::$postProcessHookObjects = []
protected

Definition at line 174 of file DatabaseConnection.php.

◆ $preProcessHookObjects

TYPO3\CMS\Core\Database\DatabaseConnection::$preProcessHookObjects = []
protected

Definition at line 169 of file DatabaseConnection.php.

◆ $store_lastBuiltQuery

TYPO3\CMS\Core\Database\DatabaseConnection::$store_lastBuiltQuery = false

Definition at line 85 of file DatabaseConnection.php.

◆ AND_Constraint

const TYPO3\CMS\Core\Database\DatabaseConnection::AND_Constraint = 'AND'

Definition at line 57 of file DatabaseConnection.php.

◆ OR_Constraint

const TYPO3\CMS\Core\Database\DatabaseConnection::OR_Constraint = 'OR'

Definition at line 64 of file DatabaseConnection.php.