Elgg
Version 4.3
|
Public Member Functions | |
__construct (DbConfig $config, QueryCache $query_cache) | |
Constructor. More... | |
resetConnections (DbConfig $config) | |
Reset the connections with new credentials. More... | |
closeConnections () | |
Close all database connections. More... | |
getConnection (string $type) | |
Gets (if required, also creates) a DB connection. More... | |
setupConnections () | |
Establish database connections. More... | |
connect (string $type= 'readwrite') | |
Establish a connection to the database server. More... | |
getData ($query, $callback=null, array $params=[]) | |
Retrieve rows from the database. More... | |
getDataRow ($query, $callback=null, array $params=[]) | |
Retrieve a single row from the database. More... | |
insertData ($query, array $params=[]) | |
Insert a row into the database. More... | |
updateData ($query, bool $get_num_rows=false, array $params=[]) | |
Update the database. More... | |
deleteData ($query, array $params=[]) | |
Delete data from the database. More... | |
trackQuery ($query, array $params, callable $callback) | |
Tracks the query count and timers for a given query. More... | |
registerDelayedQuery ($query, string $type, $callback=null, array $params=[]) | |
Queue a query for execution upon shutdown. More... | |
executeDelayedQueries () | |
Trigger all queries that were registered as "delayed" queries. More... | |
enableQueryCache () | |
Enable the query cache. More... | |
disableQueryCache () | |
Disable the query cache. More... | |
getQueryCount () | |
Get the number of queries made to the database. More... | |
getServerVersion (string $type=DbConfig::READ_WRITE) | |
Get the server version number. More... | |
isMariaDB (string $type=DbConfig::READ_WRITE) | |
Is the database MariaDB. More... | |
__get ($name) | |
Handle magic property reads. More... | |
__set ($name, $value) | |
Handle magic property writes. More... | |
Public Attributes | |
const | DELAYED_QUERY = 'q' |
const | DELAYED_TYPE = 't' |
const | DELAYED_HANDLER = 'h' |
const | DELAYED_PARAMS = 'p' |
Protected Member Functions | |
fingerprintCallback ($callback) | |
Get a string that uniquely identifies a callback during the current request. More... | |
getResults ($query, $callback=null, bool $single=false, array $params=[]) | |
Handles queries that return results, running the results through a an optional callback function. More... | |
executeQuery ($query, Connection $connection, array $params=[]) | |
Execute a query. More... | |
Protected Attributes | |
$query_cache | |
$delayed_queries = [] | |
The Elgg database.
Definition at line 25 of file Database.php.
Elgg\Database::__construct | ( | DbConfig | $config, |
QueryCache | $query_cache | ||
) |
Constructor.
Definition at line 77 of file Database.php.
Elgg\Database::__get | ( | $name | ) |
Handle magic property reads.
string | $name | Property name |
RuntimeException |
Definition at line 679 of file Database.php.
Elgg\Database::__set | ( | $name, | |
$value | |||
) |
Handle magic property writes.
string | $name | Property name |
mixed | $value | Value |
RuntimeException |
Definition at line 696 of file Database.php.
Elgg\Database::closeConnections | ( | ) |
Close all database connections.
Note: this is only meant to be used in the PHPUnit test suites
Definition at line 107 of file Database.php.
Elgg\Database::connect | ( | string | $type = 'readwrite' | ) |
Establish a connection to the database server.
Connect to the database server and use the Elgg database for a particular database link
string | $type | The type of database connection. "read", "write", or "readwrite". |
DatabaseException |
Definition at line 161 of file Database.php.
Elgg\Database::deleteData | ( | $query, | |
array | $params = [] |
||
) |
Delete data from the database.
QueryBuilder | string | $query | The SQL query to run |
array | $params | Query params. E.g. [1, 'steve'] or ['id' => 1, 'name' => 'steve'] |
Definition at line 314 of file Database.php.
Elgg\Database::disableQueryCache | ( | ) |
Disable the query cache.
This is useful for special scripts that pull large amounts of data back in single queries.
Definition at line 616 of file Database.php.
Elgg\Database::enableQueryCache | ( | ) |
Enable the query cache.
This does not take precedence over the setting.
Definition at line 604 of file Database.php.
Elgg\Database::executeDelayedQueries | ( | ) |
Trigger all queries that were registered as "delayed" queries.
This is called by the system automatically on shutdown.
Definition at line 574 of file Database.php.
|
protected |
Execute a query.
$query is executed via Connection::query. If there is an SQL error, a DatabaseException is thrown.
QueryBuilder | string | $query | The query |
Connection | $connection | The DB connection |
array | $params | Query params. E.g. [1, 'steve'] or ['id' => 1, 'name' => 'steve'] |
DatabaseException |
Definition at line 449 of file Database.php.
|
protected |
Get a string that uniquely identifies a callback during the current request.
This is used to cache queries whose results were transformed by the callback. If the callback involves object method calls of the same class, different instances will return different values.
callable | $callback | The callable value to fingerprint |
Definition at line 344 of file Database.php.
Elgg\Database::getConnection | ( | string | $type | ) |
Gets (if required, also creates) a DB connection.
string | $type | The type of link we want: "read", "write" or "readwrite". |
Definition at line 122 of file Database.php.
Elgg\Database::getData | ( | $query, | |
$callback = null , |
|||
array | $params = [] |
||
) |
Retrieve rows from the database.
Queries are executed with Elgg\Database::executeQuery()andresultsareretrievedwith@link\PDO::fetchObject().Ifacallbackfunction$callbackisdefined,eachrowwillbepassedasasingleargumentto$callback.Ifnocallbackfunctionisdefined,theentireresultsetisreturnedasanarray.@paramQueryBuilder|string$queryThequerybeingpassed.@paramcallable$callbackOptionally,thenameofafunctiontocallbacktooneachrow@paramarray$paramsQueryparams.E.g.[1,'steve']or['id'=>1,'name'=>'steve']@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.
Definition at line 210 of file Database.php.
Elgg\Database::getDataRow | ( | $query, | |
$callback = null , |
|||
array | $params = [] |
||
) |
Retrieve a single row from the database.
Similar to Elgg\Database::getData()butreturnsonlythefirstrowmatched.Ifacallbackfunction$callbackisspecified,therowwillbepassedastheonlyargumentto$callback.@paramQueryBuilder|string$queryThequerytoexecute.@paramcallable$callbackAcallbackfunctiontoapplytotherow@paramarray$paramsQueryparams.E.g.[1,'steve']or['id'=>1,'name'=>'steve']@returnmixedAsingledatabaseresultobjectortheresultofthecallbackfunction.
Definition at line 231 of file Database.php.
Elgg\Database::getQueryCount | ( | ) |
Get the number of queries made to the database.
Definition at line 625 of file Database.php.
|
protected |
Handles queries that return results, running the results through a an optional callback function.
This is for R queries (from CRUD).
QueryBuilder | string | $query | The select query to execute |
callable | $callback | An optional callback function to run on each row |
bool | $single | Return only a single result? |
array | $params | Query params. E.g. [1, 'steve'] or ['id' => 1, 'name' => 'steve'] |
RuntimeException |
Definition at line 378 of file Database.php.
Elgg\Database::getServerVersion | ( | string | $type = DbConfig::READ_WRITE | ) |
Get the server version number.
string | $type | Connection type (Config constants, e.g. Config::READ_WRITE) |
Definition at line 636 of file Database.php.
Elgg\Database::insertData | ( | $query, | |
array | $params = [] |
||
) |
Insert a row into the database.
QueryBuilder | string | $query | The query to execute. |
array | $params | Query params. E.g. [1, 'steve'] or ['id' => 1, 'name' => 'steve'] |
Definition at line 249 of file Database.php.
Elgg\Database::isMariaDB | ( | string | $type = DbConfig::READ_WRITE | ) |
Is the database MariaDB.
string | $type | Connection type (Config constants, e.g. Config::READ_WRITE) |
Definition at line 660 of file Database.php.
Elgg\Database::registerDelayedQuery | ( | $query, | |
string | $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 .
QueryBuilder | string | $query | The query to execute |
string | $type | The query type ('read' or 'write') |
callable | $callback | A callback function to pass the results array to |
array | $params | Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve'] |
Definition at line 549 of file Database.php.
Elgg\Database::resetConnections | ( | DbConfig | $config | ) |
Reset the connections with new credentials.
DbConfig | $config | DB config |
Definition at line 90 of file Database.php.
Elgg\Database::setupConnections | ( | ) |
Establish database connections.
If the configuration has been set up for multiple read/write databases, set those links up separately; otherwise just create the one database link.
Definition at line 142 of file Database.php.
Elgg\Database::trackQuery | ( | $query, | |
array | $params, | ||
callable | $callback | ||
) |
Tracks the query count and timers for a given query.
QueryBuilder | string | $query | The query |
array | $params | Optional query params |
callable | $callback | Callback to execyte during query execution |
Definition at line 506 of file Database.php.
Elgg\Database::updateData | ( | $query, | |
bool | $get_num_rows = false , |
||
array | $params = [] |
||
) |
Update the database.
QueryBuilder | string | $query | The query to run. |
bool | $get_num_rows | Return the number of rows affected (default: false). |
array | $params | Query params. E.g. [1, 'steve'] or ['id' => 1, 'name' => 'steve'] |
Definition at line 281 of file Database.php.
|
protected |
Definition at line 64 of file Database.php.
|
protected |
Definition at line 55 of file Database.php.
const Elgg\Database::DELAYED_HANDLER = 'h' |
Definition at line 32 of file Database.php.
const Elgg\Database::DELAYED_PARAMS = 'p' |
Definition at line 33 of file Database.php.
const Elgg\Database::DELAYED_QUERY = 'q' |
Definition at line 30 of file Database.php.
const Elgg\Database::DELAYED_TYPE = 't' |
Definition at line 31 of file Database.php.