Elgg  Version 3.0
Public Member Functions | List of all members
Elgg\Application\Database Class Reference

Public Member Functions

 __construct (ElggDb $db)
 Constructor. More...
 
 getData ($query, $callback= '', array $params=[])
 Retrieve rows from the database. More...
 
 getDataRow ($query, $callback= '', array $params=[])
 Retrieve a single row from the database. More...
 
 insertData ($query, array $params=[])
 Insert a row into the database. More...
 
 updateData ($query, $getNumRows=false, array $params=[])
 Update the database. More...
 
 deleteData ($query, array $params=[])
 Delete data from the database. More...
 
 sanitizeInt ($value, $signed=true)
 Sanitizes an integer value for use in a query. More...
 
 sanitizeString ($value)
 Sanitizes a string for use in a query. More...
 
 getConnection ($type)
 Gets (if required, also creates) a DB connection. More...
 
 registerDelayedQuery ($query, $type, $callback=null, array $params=[])
 Queue a query for execution upon shutdown. More...
 
 __get ($name)
 Handle magic property reads. More...
 
 __set ($name, $value)
 Handle magic property writes. More...
 

Detailed Description

Definition at line 16 of file Database.php.

Constructor & Destructor Documentation

Elgg\Application\Database::__construct ( ElggDb  $db)

Constructor.

Parameters
ElggDb$dbThe Elgg database

Definition at line 30 of file Database.php.

Member Function Documentation

Elgg\Application\Database::__get (   $name)

Handle magic property reads.

Parameters
string$nameProperty name
Returns
mixed

Definition at line 183 of file Database.php.

Elgg\Application\Database::__set (   $name,
  $value 
)

Handle magic property writes.

Parameters
string$nameProperty name
mixed$valueValue
Returns
void

Definition at line 194 of file Database.php.

Elgg\Application\Database::deleteData (   $query,
array  $params = [] 
)

Delete data from the database.

Note
Altering the DB invalidates all queries in query cache.
Parameters
string$queryThe SQL query to run
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
int The number of affected rows
Exceptions
DatabaseException

Definition at line 118 of file Database.php.

Elgg\Application\Database::getConnection (   $type)

Gets (if required, also creates) a DB connection.

Parameters
string$typeThe type of link we want: "read", "write" or "readwrite".
Returns
Connection
Exceptions
DatabaseException

Definition at line 155 of file Database.php.

Elgg\Application\Database::getData (   $query,
  $callback = '',
array  $params = [] 
)

Retrieve rows from the database.

Queries are executed with Elgg\Database::executeQuery()andresultsareretrievedwith@link\PDO::fetchObject().Ifacallbackfunction$callbackisdefined,eachrowwillbepassedasasingleargumentto$callback.Ifnocallbackfunctionisdefined,theentireresultsetisreturnedasanarray.@paramstring$queryThequerybeingpassed.@paramcallable$callbackOptionally,thenameofafunctiontocallbacktooneachrow@paramarray$paramsQueryparams.E.g.[1,'steve']or[':id'=>1,':name'=>'steve']@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.@throwsDatabaseException

Definition at line 51 of file Database.php.

Elgg\Application\Database::getDataRow (   $query,
  $callback = '',
array  $params = [] 
)

Retrieve a single row from the database.

Similar to Elgg\Database::getData()butreturnsonlythefirstrowmatched.Ifacallbackfunction$callbackisspecified,therowwillbepassedastheonlyargumentto$callback.@paramstring$queryThequerytoexecute.@paramcallable$callbackAcallbackfunctiontoapplytotherow@paramarray$paramsQueryparams.E.g.[1,'steve']or[':id'=>1,':name'=>'steve']@returnmixedAsingledatabaseresultobjectortheresultofthecallbackfunction.@throwsDatabaseException

Definition at line 69 of file Database.php.

Elgg\Application\Database::insertData (   $query,
array  $params = [] 
)

Insert a row into the database.

Note
Altering the DB invalidates all queries in the query cache.
Parameters
string$queryThe query to execute.
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
int|false The database id of the inserted row if a AUTO_INCREMENT field is defined, 0 if not, and false on failure.
Exceptions
DatabaseException

Definition at line 85 of file Database.php.

Elgg\Application\Database::registerDelayedQuery (   $query,
  $type,
  $callback = null,
array  $params = [] 
)

Queue a query for execution upon shutdown.

You can specify a callback if you care about the result. This function will always be passed a .

Parameters
string$queryThe query to execute
string$typeThe query type ('read' or 'write')
callable$callbackA callback function to pass the results array to
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
boolean Whether registering was successful.

Definition at line 173 of file Database.php.

Elgg\Application\Database::sanitizeInt (   $value,
  $signed = true 
)

Sanitizes an integer value for use in a query.

Parameters
int$valueValue to sanitize
bool$signedWhether negative values are allowed (default: true)
Returns
int

Definition at line 130 of file Database.php.

Elgg\Application\Database::sanitizeString (   $value)

Sanitizes a string for use in a query.

Parameters
string$valueValue to escape
Returns
string
Exceptions
DatabaseException

Definition at line 142 of file Database.php.

Elgg\Application\Database::updateData (   $query,
  $getNumRows = false,
array  $params = [] 
)

Update the database.

Note
Altering the DB invalidates all queries in the query cache.
WARNING! update_data() has the 2nd and 3rd arguments reversed.
Parameters
string$queryThe query to run.
bool$getNumRowsReturn the number of rows affected (default: false).
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
bool|int
Exceptions
DatabaseException

Definition at line 103 of file Database.php.


The documentation for this class was generated from the following file: