PHP Класс Contao\Database

The class is responsible for connecting to the database, listing tables and fields, handling transactions and locking tables. It also creates the related Database\Statement and Database\Result objects. Usage: $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM tl_user WHERE id=?"); $res = $stmt->execute(4);
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$arrCache array Cache
$arrInstances array Object instances (Singleton)
$blnDisableAutocommit boolean Disable autocommit
$resConnection Doctrine\DBAL\Connection Connection ID

Открытые методы

Метод Описание
__clone ( ) Prevent cloning of the object (Singleton)
__destruct ( ) Close the database connection
__get ( string $strKey ) : string | null Return an object property
beginTransaction ( ) Begin a transaction
commitTransaction ( ) Commit a transaction
execute ( string $strQuery ) : Result | object Execute a query and return a Database\Result object
executeCached ( string $strQuery ) : Result | object Always execute the query and add or replace an existing cache entry
executeUncached ( string $strQuery ) : Result | object Execute a query and do not cache the result
fieldExists ( string $strField, string $strTable, boolean $blnNoCache = false ) : boolean Determine if a particular column exists
findInSet ( string $strKey, mixed $varSet, boolean $blnIsField = false ) : string Auto-generate a FIND_IN_SET() statement
getChildRecords ( mixed $arrParentIds, string $strTable, boolean $blnSorting = false, array $arrReturn = [], string $strWhere = '' ) : array Return the IDs of all child records of a particular record (see #2475)
getFieldNames ( string $strTable, boolean $blnNoCache = false ) : array Return the field names of a particular table as array
getInstance ( array $arrCustomConfig = null ) : Database Instantiate the Database object (Factory)
getNextId ( string $strTable ) : integer Return the next autoincrement ID of a table
getParentRecords ( integer $intId, string $strTable ) : array Return the IDs of all parent records of a particular record
getSizeOf ( string $strTable ) : integer Return the table size in bytes
getUuid ( ) : string Return a universal unique identifier
indexExists ( string $strName, string $strTable, boolean $blnNoCache = false ) : boolean Determine if a particular index exists
isUniqueValue ( string $strTable, string $strField, mixed $varValue, integer $intId = null ) : boolean Check whether a field value in the database is unique
listFields ( string $strTable, boolean $blnNoCache = false ) : array Return all columns of a particular table as array
listTables ( string $strDatabase = null, boolean $blnNoCache = false ) : array Return all tables as array
lockTables ( array $arrTables ) Lock one or more tables
prepare ( string $strQuery ) : Statement Prepare a query and return a Database\Statement object
query ( string $strQuery ) : Result | object Execute a raw query and return a Database\Result object
rollbackTransaction ( ) Rollback a transaction
setDatabase ( string $strDatabase ) Change the current database
tableExists ( string $strTable, string $strDatabase = null, boolean $blnNoCache = false ) : boolean Determine if a particular database table exists
unlockTables ( ) Unlock all tables

Защищенные методы

Метод Описание
__construct ( array $arrConfig ) Establish the database connection

Описание методов

__clone() закрытый публичный метод

Prevent cloning of the object (Singleton)
final public __clone ( )

__construct() защищенный метод

Establish the database connection
protected __construct ( array $arrConfig )
$arrConfig array The configuration array

__destruct() публичный метод

Close the database connection
public __destruct ( )

__get() публичный метод

Return an object property
public __get ( string $strKey ) : string | null
$strKey string The property name
Результат string | null The property value

beginTransaction() публичный метод

Begin a transaction
public beginTransaction ( )

commitTransaction() публичный метод

Commit a transaction
public commitTransaction ( )

execute() публичный метод

Execute a query and return a Database\Result object
public execute ( string $strQuery ) : Result | object
$strQuery string The query string
Результат Contao\Database\Result | object The Database\Result object

executeCached() публичный метод

Always execute the query and add or replace an existing cache entry
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database::execute() instead.
public executeCached ( string $strQuery ) : Result | object
$strQuery string The query string
Результат Contao\Database\Result | object The Database\Result object

executeUncached() публичный метод

Execute a query and do not cache the result
Устаревший: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database::execute() instead.
public executeUncached ( string $strQuery ) : Result | object
$strQuery string The query string
Результат Contao\Database\Result | object The Database\Result object

fieldExists() публичный метод

Determine if a particular column exists
public fieldExists ( string $strField, string $strTable, boolean $blnNoCache = false ) : boolean
$strField string The field name
$strTable string The table name
$blnNoCache boolean If true, the cache will be bypassed
Результат boolean True if the field exists

findInSet() публичный метод

Auto-generate a FIND_IN_SET() statement
public findInSet ( string $strKey, mixed $varSet, boolean $blnIsField = false ) : string
$strKey string The field name
$varSet mixed The set to find the key in
$blnIsField boolean If true, the set will not be quoted
Результат string The FIND_IN_SET() statement

getChildRecords() публичный метод

Return the IDs of all child records of a particular record (see #2475)
Автор: Andreas Schempp
public getChildRecords ( mixed $arrParentIds, string $strTable, boolean $blnSorting = false, array $arrReturn = [], string $strWhere = '' ) : array
$arrParentIds mixed An array of parent IDs
$strTable string The table name
$blnSorting boolean True if the table has a sorting field
$arrReturn array The array to be returned
$strWhere string Additional WHERE condition
Результат array An array of child record IDs

getFieldNames() публичный метод

Return the field names of a particular table as array
public getFieldNames ( string $strTable, boolean $blnNoCache = false ) : array
$strTable string The table name
$blnNoCache boolean If true, the cache will be bypassed
Результат array An array of field names

getInstance() публичный статический метод

Instantiate the Database object (Factory)
public static getInstance ( array $arrCustomConfig = null ) : Database
$arrCustomConfig array A configuration array
Результат Database The Database object

getNextId() публичный метод

Return the next autoincrement ID of a table
public getNextId ( string $strTable ) : integer
$strTable string The table name
Результат integer The autoincrement ID

getParentRecords() публичный метод

Return the IDs of all parent records of a particular record
public getParentRecords ( integer $intId, string $strTable ) : array
$intId integer The ID of the record
$strTable string The table name
Результат array An array of parent record IDs

getSizeOf() публичный метод

Return the table size in bytes
public getSizeOf ( string $strTable ) : integer
$strTable string The table name
Результат integer The table size in bytes

getUuid() публичный метод

Return a universal unique identifier
public getUuid ( ) : string
Результат string The UUID string

indexExists() публичный метод

Determine if a particular index exists
public indexExists ( string $strName, string $strTable, boolean $blnNoCache = false ) : boolean
$strName string The index name
$strTable string The table name
$blnNoCache boolean If true, the cache will be bypassed
Результат boolean True if the index exists

isUniqueValue() публичный метод

Check whether a field value in the database is unique
public isUniqueValue ( string $strTable, string $strField, mixed $varValue, integer $intId = null ) : boolean
$strTable string The table name
$strField string The field name
$varValue mixed The field value
$intId integer The ID of a record to exempt
Результат boolean True if the field value is unique

listFields() публичный метод

Return all columns of a particular table as array
public listFields ( string $strTable, boolean $blnNoCache = false ) : array
$strTable string The table name
$blnNoCache boolean If true, the cache will be bypassed
Результат array An array of column names

listTables() публичный метод

Return all tables as array
public listTables ( string $strDatabase = null, boolean $blnNoCache = false ) : array
$strDatabase string The database name
$blnNoCache boolean If true, the cache will be bypassed
Результат array An array of table names

lockTables() публичный метод

Lock one or more tables
public lockTables ( array $arrTables )
$arrTables array An array of table names to be locked

prepare() публичный метод

Prepare a query and return a Database\Statement object
public prepare ( string $strQuery ) : Statement
$strQuery string The query string
Результат Contao\Database\Statement The Database\Statement object

query() публичный метод

Execute a raw query and return a Database\Result object
public query ( string $strQuery ) : Result | object
$strQuery string The query string
Результат Contao\Database\Result | object The Database\Result object

rollbackTransaction() публичный метод

Rollback a transaction
public rollbackTransaction ( )

setDatabase() публичный метод

Change the current database
public setDatabase ( string $strDatabase )
$strDatabase string The name of the target database

tableExists() публичный метод

Determine if a particular database table exists
public tableExists ( string $strTable, string $strDatabase = null, boolean $blnNoCache = false ) : boolean
$strTable string The table name
$strDatabase string The optional database name
$blnNoCache boolean If true, the cache will be bypassed
Результат boolean True if the table exists

unlockTables() публичный метод

Unlock all tables
public unlockTables ( )

Описание свойств

$arrCache защищенное свойство

Cache
protected array $arrCache
Результат array

$arrInstances защищенное статическое свойство

Object instances (Singleton)
protected static array $arrInstances
Результат array

$blnDisableAutocommit защищенное свойство

Disable autocommit
protected bool $blnDisableAutocommit
Результат boolean

$resConnection защищенное свойство

Connection ID
protected Connection,Doctrine\DBAL $resConnection
Результат Doctrine\DBAL\Connection