Elgg
Version 6.0
|
Public Member Functions | |
__construct (DbConfig $db_config, protected QueryCache $query_cache, protected Config $config) | |
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 (QueryBuilder $query, $callback=null) | |
Retrieve rows from the database. More... | |
getDataRow (QueryBuilder $query, $callback=null) | |
Retrieve a single row from the database. More... | |
insertData (QueryBuilder $query) | |
Insert a row into the database. More... | |
updateData (QueryBuilder $query, bool $get_num_rows=false) | |
Update the database. More... | |
deleteData (QueryBuilder $query) | |
Delete data from the database. More... | |
trackQuery (QueryBuilder $query, callable $callback) | |
Tracks the query count and timers for a given query. More... | |
registerDelayedQuery (QueryBuilder $query, $callback=null) | |
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... | |
isMySQL (string $type=DbConfig::READ_WRITE) | |
Is the database MySQL. More... | |
__get ($name) | |
Handle magic property reads. More... | |
__set ($name, $value) | |
Handle magic property writes. More... | |
Public Attributes | |
const | DELAYED_QUERY = 'q' |
const | DELAYED_HANDLER = 'h' |
Protected Member Functions | |
fingerprintCallback ($callback) | |
Get a string that uniquely identifies a callback during the current request. More... | |
getResults (QueryBuilder $query, $callback=null, bool $single=false) | |
Handles queries that return results, running the results through a an optional callback function. More... | |
executeQuery (QueryBuilder $query) | |
Execute a query. More... | |
Protected Attributes | |
$table_prefix | |
array | $connections = [] |
int | $query_count = 0 |
$delayed_queries = [] | |
$db_config | |
The Elgg database.
Definition at line 26 of file Database.php.
Elgg\Database::__construct | ( | DbConfig | $db_config, |
protected QueryCache | $query_cache, | ||
protected Config | $config | ||
) |
Elgg\Database::__get | ( | $name | ) |
Handle magic property reads.
string | $name | Property name |
RuntimeException |
Definition at line 596 of file Database.php.
Elgg\Database::__set | ( | $name, | |
$value | |||
) |
Handle magic property writes.
string | $name | Property name |
mixed | $value | Value |
RuntimeException |
Definition at line 613 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 98 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 152 of file Database.php.
Elgg\Database::deleteData | ( | QueryBuilder | $query | ) |
Delete data from the database.
QueryBuilder | $query | The SQL query to run |
Definition at line 286 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 540 of file Database.php.
Elgg\Database::enableQueryCache | ( | ) |
Enable the query cache.
This does not take precedence over the setting.
Definition at line 528 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 500 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 | $query | The query |
DatabaseException |
Definition at line 402 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 309 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 113 of file Database.php.
Elgg\Database::getData | ( | QueryBuilder | $query, |
$callback = null |
|||
) |
Retrieve rows from the database.
Queries are executed with Elgg\Database::executeQuery()andresultsareretrievedwith@link\PDO::fetchObject().Ifacallbackfunction$callbackisdefined,eachrowwillbepassedasasingleargumentto$callback.Ifnocallbackfunctionisdefined,theentireresultsetisreturnedasanarray.@paramQueryBuilder$queryThequerybeingpassed.@paramcallable$callbackOptionally,thenameofafunctiontocallbacktooneachrow@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.
Definition at line 200 of file Database.php.
Elgg\Database::getDataRow | ( | QueryBuilder | $query, |
$callback = null |
|||
) |
Retrieve a single row from the database.
Similar to Elgg\Database::getData()butreturnsonlythefirstrowmatched.Ifacallbackfunction$callbackisspecified,therowwillbepassedastheonlyargumentto$callback.@paramQueryBuilder$queryThequerytoexecute.@paramcallable$callbackAcallbackfunctiontoapplytotherow@returnmixedAsingledatabaseresultobjectortheresultofthecallbackfunction.
Definition at line 216 of file Database.php.
Elgg\Database::getQueryCount | ( | ) |
Get the number of queries made to the database.
Definition at line 549 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 | $query | The select query to execute |
callable | $callback | An optional callback function to run on each row |
bool | $single | Return only a single result? |
RuntimeException |
Definition at line 342 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 560 of file Database.php.
Elgg\Database::insertData | ( | QueryBuilder | $query | ) |
Insert a row into the database.
QueryBuilder | $query | The query to execute. |
Definition at line 229 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 571 of file Database.php.
Elgg\Database::isMySQL | ( | string | $type = DbConfig::READ_WRITE | ) |
Is the database MySQL.
string | $type | Connection type (Config constants, e.g. Config::READ_WRITE) |
Definition at line 584 of file Database.php.
Elgg\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 .
QueryBuilder | $query | The query to execute |
callable | $callback | A callback function to pass the results array to |
Definition at line 469 of file Database.php.
Elgg\Database::resetConnections | ( | DbConfig | $config | ) |
Reset the connections with new credentials.
DbConfig | $config | DB config |
Definition at line 81 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 133 of file Database.php.
Elgg\Database::trackQuery | ( | QueryBuilder | $query, |
callable | $callback | ||
) |
Tracks the query count and timers for a given query.
QueryBuilder | $query | The query |
callable | $callback | Callback to execyte during query execution |
Definition at line 431 of file Database.php.
Elgg\Database::updateData | ( | QueryBuilder | $query, |
bool | $get_num_rows = false |
||
) |
Update the database.
QueryBuilder | $query | The query to run. |
bool | $get_num_rows | Return the number of rows affected (default: false). |
Definition at line 261 of file Database.php.
|
protected |
Definition at line 42 of file Database.php.
|
protected |
Definition at line 61 of file Database.php.
|
protected |
Definition at line 56 of file Database.php.
|
protected |
Definition at line 47 of file Database.php.
|
protected |
Definition at line 37 of file Database.php.
const Elgg\Database::DELAYED_HANDLER = 'h' |
Definition at line 32 of file Database.php.
const Elgg\Database::DELAYED_QUERY = 'q' |
Definition at line 31 of file Database.php.