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);
파일 보기 프로젝트 열기: contao/core-bundle 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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