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

Public Member Functions

 __construct (protected ElggDb $db)
 Constructor. More...
 
 getData (QueryBuilder $query, $callback='')
 Retrieve rows from the database. More...
 
 getDataRow (QueryBuilder $query, $callback='')
 Retrieve a single row from the database. More...
 
 insertData (QueryBuilder $query)
 Insert a row into the database. More...
 
 updateData (QueryBuilder $query, bool $getNumRows=false)
 Update the database. More...
 
 deleteData (QueryBuilder $query)
 Delete data from the database. More...
 
 getConnection ($type)
 Gets (if required, also creates) a DB connection. More...
 
 registerDelayedQuery (QueryBuilder $query, $callback=null)
 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

◆ __construct()

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

Constructor.

Parameters
ElggDb$dbThe Elgg database

Definition at line 23 of file Database.php.

Member Function Documentation

◆ __get()

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

Handle magic property reads.

Parameters
string$nameProperty name
Returns
mixed

Definition at line 136 of file Database.php.

◆ __set()

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

Handle magic property writes.

Parameters
string$nameProperty name
mixed$valueValue
Returns
void

Definition at line 147 of file Database.php.

◆ deleteData()

Elgg\Application\Database::deleteData ( QueryBuilder  $query)

Delete data from the database.

Note
Altering the DB invalidates all queries in query cache.
Parameters
QueryBuilder$queryThe SQL query to run
Returns
int The number of affected rows

Definition at line 98 of file Database.php.

◆ getConnection()

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 110 of file Database.php.

◆ getData()

Elgg\Application\Database::getData ( QueryBuilder  $query,
  $callback = '' 
)

Retrieve rows from the database.

Queries are executed with () and results are retrieved with (). If a callback function $callback is defined, each row will be passed as a single argument to $callback. If no callback function is defined, the entire result set is returned as an array.

Parameters
QueryBuilder$queryThe query being passed.
callable$callbackOptionally, the name of a function to call back to on each row
Returns
array An array of database result objects or callback function results. If the query returned nothing, an empty array.

Definition at line 41 of file Database.php.

◆ getDataRow()

Elgg\Application\Database::getDataRow ( QueryBuilder  $query,
  $callback = '' 
)

Retrieve a single row from the database.

Similar to () but returns only the first row matched. If a callback function $callback is specified, the row will be passed as the only argument to $callback.

Parameters
QueryBuilder$queryThe query to execute.
callable$callbackA callback function to apply to the row
Returns
mixed A single database result object or the result of the callback function.

Definition at line 57 of file Database.php.

◆ insertData()

Elgg\Application\Database::insertData ( QueryBuilder  $query)

Insert a row into the database.

Note
Altering the DB invalidates all queries in the query cache.
Parameters
QueryBuilder$queryThe query to execute
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 71 of file Database.php.

◆ registerDelayedQuery()

Elgg\Application\Database::registerDelayedQuery ( QueryBuilder  $query,
  $callback = null 
)

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 \Doctrine\DBAL\Driver\Statement.

Parameters
QueryBuilder$queryThe query to execute
callable$callbackA callback function to pass the results array to
Returns
void

Definition at line 126 of file Database.php.

◆ updateData()

Elgg\Application\Database::updateData ( QueryBuilder  $query,
bool  $getNumRows = false 
)

Update the database.

Note
Altering the DB invalidates all queries in the query cache.
Parameters
QueryBuilder$queryThe query to run.
bool$getNumRowsReturn the number of rows affected (default: false).
Returns
bool|int

Definition at line 85 of file Database.php.


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