Elgg
Version 2.3
|
Public Member Functions | |
__construct (\Elgg\Database\Config $config,\Elgg\Logger $logger=null) | |
Constructor. More... | |
setLogger (Logger $logger) | |
Set the logger object. More... | |
setupConnections () | |
Establish database connections. More... | |
connect ($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, $get_num_rows=false, array $params=[]) | |
Update the database. More... | |
deleteData ($query, array $params=[]) | |
Delete data from the database. More... | |
fingerprintCallback ($callback) | |
Get a string that uniquely identifies a callback during the current request. More... | |
runSqlScript ($scriptlocation) | |
Runs a full database script from disk. More... | |
registerDelayedQuery ($query, $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... | |
assertInstalled () | |
Test that the Elgg database is installed. More... | |
getQueryCount () | |
Get the number of queries made to the database. More... | |
getTablePrefix () | |
Get the value of the "prefix" property. 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... | |
getServerVersion ($type) | |
Get the server version number. 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 | |
getConnection ($type) | |
Gets (if required, also creates) a DB connection. More... | |
getResults ($query, $callback=null, $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... | |
invalidateQueryCache () | |
Invalidate the query cache. More... | |
Elgg\Database::__construct | ( | \Elgg\Database\Config | $config, |
\Elgg\Logger | $logger = null |
||
) |
Constructor.
\Elgg\Database\Config | $config | Database configuration |
\Elgg\Logger | $logger | The logger |
Definition at line 88 of file Database.php.
Elgg\Database::__get | ( | $name | ) |
Handle magic property reads.
string | $name | Property name |
Definition at line 736 of file Database.php.
Elgg\Database::__set | ( | $name, | |
$value | |||
) |
Handle magic property writes.
string | $name | Property name |
mixed | $value | Value |
Definition at line 751 of file Database.php.
Elgg\Database::assertInstalled | ( | ) |
Test that the Elgg database is installed.
Definition at line 633 of file Database.php.
Elgg\Database::connect | ( | $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". |
Definition at line 158 of file Database.php.
Elgg\Database::deleteData | ( | $query, | |
array | $params = [] |
||
) |
Delete data from the database.
string | $query | The SQL query to run |
array | $params | Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve'] |
Definition at line 297 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 608 of file Database.php.
Elgg\Database::enableQueryCache | ( | ) |
Enable the query cache.
This does not take precedence over the setting.
Definition at line 592 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 560 of file Database.php.
|
protected |
Execute a query.
$query is executed via Connection::query. If there is an SQL error, a DatabaseException is thrown.
string | $query | The query |
Connection | $connection | The DB connection |
array | $params | Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve'] |
Definition at line 426 of file Database.php.
Elgg\Database::fingerprintCallback | ( | $callback | ) |
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 324 of file Database.php.
|
protected |
Gets (if required, also creates) a DB connection.
string | $type | The type of link we want: "read", "write" or "readwrite". |
Definition at line 117 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.@paramstring$queryThequerybeingpassed.@paramcallable$callbackOptionally,thenameofafunctiontocallbacktooneachrow@paramarray$paramsQueryparams.E.g.[1,'steve']or[':id'=>1,':name'=>'steve']@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.@throws\DatabaseException
Definition at line 208 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.@paramstring$queryThequerytoexecute.@paramcallable$callbackAcallbackfunctiontoapplytotherow@paramarray$paramsQueryparams.E.g.[1,'steve']or[':id'=>1,':name'=>'steve']@returnmixedAsingledatabaseresultobjectortheresultofthecallbackfunction.@throws\DatabaseException
Definition at line 226 of file Database.php.
Elgg\Database::getQueryCount | ( | ) |
Get the number of queries made to the database.
Definition at line 655 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).
string | $query | The select query to execute |
string | $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'] |
Definition at line 354 of file Database.php.
Elgg\Database::getServerVersion | ( | $type | ) |
Get the server version number.
string | $type | Connection type (Config constants, e.g. Config::READ_WRITE) |
Definition at line 721 of file Database.php.
Elgg\Database::getTablePrefix | ( | ) |
Get the value of the "prefix" property.
Definition at line 667 of file Database.php.
Elgg\Database::insertData | ( | $query, | |
array | $params = [] |
||
) |
Insert a row into the database.
string | $query | The query to execute. |
array | $params | Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve'] |
Definition at line 242 of file Database.php.
|
protected |
Elgg\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 .
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 537 of file Database.php.
Elgg\Database::runSqlScript | ( | $scriptlocation | ) |
Runs a full database script from disk.
The file specified should be a standard SQL file as created by mysqldump or similar. Statements must be terminated with ; and a newline character (
or
).
The special string 'prefix_' is replaced with the database prefix as defined in ->tablePrefix.
string | $scriptlocation | The full path to the script |
Definition at line 485 of file Database.php.
Elgg\Database::sanitizeInt | ( | $value, | |
$signed = true |
|||
) |
Sanitizes an integer value for use in a query.
int | $value | Value to sanitize |
bool | $signed | Whether negative values are allowed (default: true) |
Definition at line 682 of file Database.php.
Elgg\Database::sanitizeString | ( | $value | ) |
Sanitizes a string for use in a query.
string | $value | Value to escape |
Definition at line 702 of file Database.php.
Elgg\Database::setLogger | ( | Logger | $logger | ) |
Set the logger object.
Logger | $logger | The logger |
Definition at line 105 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 138 of file Database.php.
Elgg\Database::updateData | ( | $query, | |
$get_num_rows = false , |
|||
array | $params = [] |
||
) |
Update the database.
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 270 of file Database.php.
const Elgg\Database::DELAYED_HANDLER = 'h' |
Definition at line 22 of file Database.php.
const Elgg\Database::DELAYED_PARAMS = 'p' |
Definition at line 23 of file Database.php.
const Elgg\Database::DELAYED_QUERY = 'q' |
Definition at line 20 of file Database.php.
const Elgg\Database::DELAYED_TYPE = 't' |
Definition at line 21 of file Database.php.