Elgg  Version 4.x
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...
 
 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 15 of file Database.php.

Constructor & Destructor Documentation

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

Constructor.

Parameters
ElggDb$dbThe Elgg database

Definition at line 29 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 150 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 161 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

Definition at line 110 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

Definition at line 122 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.

Definition at line 49 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.

Definition at line 66 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.

Definition at line 81 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 140 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.
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

Definition at line 96 of file Database.php.


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