PHP Class Contao\Database\Statement

The class creates the database queries replacing the wildcards and escaping the values. It then executes the query and returns a result object. Usage: $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM tl_member WHERE city=?"); $stmt->limit(10); $res = $stmt->execute('London');
Mostrar archivo Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrCache array Result cache
$blnDisableAutocommit boolean Autocommit indicator
$resConnection Doctrine\DBAL\Connection Connection ID
$statement Doctrine\DBAL\Driver\Statement Database statement
$strQuery string Query string

Public Methods

Method Description
__construct ( Doctrine\DBAL\Connection $resConnection, boolean $blnDisableAutocommit = false ) Validate the connection resource and store the query string
__get ( string $strKey ) : mixed | null Return an object property
execute ( ) : Result | object Execute the query and return the result object
executeCached ( ) : Result Always execute the query and add or replace an existing cache entry
executeUncached ( ) : Result Bypass the cache and always execute the query
explain ( ) : string Explain the current query
limit ( integer $intRows, integer $intOffset ) : Statement Handle limit and offset
prepare ( string $strQuery ) : Statement Prepare a query string so the following functions can handle it
query ( string $strQuery = '' ) : Result | Statement Directly send a query string to the database
set ( array $arrParams ) : Statement Autogenerate the SET/VALUES subpart of a query from an associative array

Protected Methods

Method Description
escapeParams ( array $arrValues ) : array Escape the values and serialize objects and arrays
replaceWildcards ( array $arrValues ) Replace the wildcards in the query string

Method Details

__construct() public method

Validate the connection resource and store the query string
public __construct ( Doctrine\DBAL\Connection $resConnection, boolean $blnDisableAutocommit = false )
$resConnection Doctrine\DBAL\Connection The connection resource
$blnDisableAutocommit boolean Optionally disable autocommitting

__get() public method

Return an object property
public __get ( string $strKey ) : mixed | null
$strKey string The property name
return mixed | null The property value or null

escapeParams() protected method

Escape the values and serialize objects and arrays
protected escapeParams ( array $arrValues ) : array
$arrValues array The values array
return array The array with the escaped values

execute() public method

Execute the query and return the result object
public execute ( ) : Result | object
return Result | object The result object

executeCached() public method

Always execute the query and add or replace an existing cache entry
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database\Statement::execute() instead.
public executeCached ( ) : Result
return Result The result object

executeUncached() public method

Bypass the cache and always execute the query
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Database\Statement::execute() instead.
public executeUncached ( ) : Result
return Result The result object

explain() public method

Explain the current query
public explain ( ) : string
return string The explanation string

limit() public method

Handle limit and offset
public limit ( integer $intRows, integer $intOffset ) : Statement
$intRows integer The maximum number of rows
$intOffset integer The number of rows to skip
return Statement The statement object

prepare() public method

Prepare a query string so the following functions can handle it
public prepare ( string $strQuery ) : Statement
$strQuery string The query string
return Statement The statement object

query() public method

Directly send a query string to the database
public query ( string $strQuery = '' ) : Result | Statement
$strQuery string The query string
return Result | Statement The result object or the statement object if there is no result set

replaceWildcards() protected method

Replace the wildcards in the query string
protected replaceWildcards ( array $arrValues )
$arrValues array The values array

set() public method

Usage: $set = array( 'firstname' => 'Leo', 'lastname' => 'Feyer' ); $stmt->prepare("UPDATE tl_member %s")->set($set);
public set ( array $arrParams ) : Statement
$arrParams array The associative array
return Statement The statement object

Property Details

$arrCache protected_oe static_oe property

Result cache
protected static array $arrCache
return array

$blnDisableAutocommit protected_oe property

Autocommit indicator
protected bool $blnDisableAutocommit
return boolean

$resConnection protected_oe property

Connection ID
protected Connection,Doctrine\DBAL $resConnection
return Doctrine\DBAL\Connection

$statement protected_oe property

Database statement
protected Statement,Doctrine\DBAL\Driver $statement
return Doctrine\DBAL\Driver\Statement

$strQuery protected_oe property

Query string
protected string $strQuery
return string