Elgg
Version 1.11
|
Public Member Functions | |
__construct (\Elgg\Database\Config $config,\Elgg\Logger $logger) | |
Constructor. More... | |
getLink ($type) | |
Gets (if required, also creates) a database link resource. More... | |
setupConnections () | |
Establish database connections. More... | |
establishLink ($dblinkname="readwrite") | |
Establish a connection to the database server. More... | |
getData ($query, $callback= '') | |
Retrieve rows from the database. More... | |
getDataRow ($query, $callback= '') | |
Retrieve a single row from the database. More... | |
insertData ($query) | |
Insert a row into the database. More... | |
updateData ($query, $getNumRows=false) | |
Update the database. More... | |
deleteData ($query) | |
Delete data from the database. More... | |
fingerprintCallback ($callback) | |
Get a string that uniquely identifies a callback during the current request. More... | |
executeQuery ($query, $dblink) | |
Execute a query. More... | |
runSqlScript ($scriptlocation) | |
Runs a full database script from disk. More... | |
registerDelayedQuery ($query, $type, $handler="") | |
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 prefix for Elgg's tables. 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... | |
Public Attributes | |
global | $ELGG_PLUGINS_PROVIDES_CACHE |
global | $SUBTYPE_CACHE |
Cache subtypes and related class names. More... | |
$SUBTYPE_CACHE = null | |
global | $USERNAME_TO_GUID_MAP_CACHE |
$USERNAME_TO_GUID_MAP_CACHE = array() | |
Protected Member Functions | |
getResults ($query, $callback=null, $single=false) | |
Handles queries that return results, running the results through a an optional callback function. More... | |
invalidateQueryCache () | |
Invalidate the query cache. More... | |
Definition at line 15 of file Database.php.
Elgg\Database::__construct | ( | \Elgg\Database\Config | $config, |
\Elgg\Logger | $logger | ||
) |
Constructor.
\Elgg\Database\Config | $config | Database configuration |
\Elgg\Logger | $logger | The logger |
Definition at line 76 of file Database.php.
Elgg\Database::assertInstalled | ( | ) |
Test that the Elgg database is installed.
Definition at line 582 of file Database.php.
Elgg\Database::deleteData | ( | $query | ) |
Delete data from the database.
string | $query | The SQL query to run |
Definition at line 262 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 560 of file Database.php.
Elgg\Database::enableQueryCache | ( | ) |
Enable the query cache.
This does not take precedence over the setting.
Definition at line 545 of file Database.php.
Elgg\Database::establishLink | ( | $dblinkname = "readwrite" | ) |
Establish a connection to the database server.
Connect to the database server and use the Elgg database for a particular database link
string | $dblinkname | The type of database connection. Used to identify the resource: "read", "write", or "readwrite". |
Definition at line 139 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 513 of file Database.php.
Elgg\Database::executeQuery | ( | $query, | |
$dblink | |||
) |
Execute a query.
$query is executed via mysql_query(). If there is an SQL error, a DatabaseException is thrown.
string | $query | The query |
resource | $dblink | The DB link |
Definition at line 391 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 290 of file Database.php.
Elgg\Database::getData | ( | $query, | |
$callback = '' |
|||
) |
Retrieve rows from the database.
Queries are executed with Elgg\Database::executeQuery()andresultsareretrievedwith@linkmysql_fetch_object().Ifacallbackfunction$callbackisdefined,eachrowwillbepassedasasingleargumentto$callback.Ifnocallbackfunctionisdefined,theentireresultsetisreturnedasanarray.@parammixed$queryThequerybeingpassed.@paramstring$callbackOptionally,thenameofafunctiontocallbacktooneachrow@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.@throws\DatabaseException
Definition at line 175 of file Database.php.
Elgg\Database::getDataRow | ( | $query, | |
$callback = '' |
|||
) |
Retrieve a single row from the database.
Similar to Elgg\Database::getData()butreturnsonlythefirstrowmatched.Ifacallbackfunction$callbackisspecified,therowwillbepassedastheonlyargumentto$callback.@parammixed$queryThequerytoexecute.@paramstring$callbackAcallbackfunction@returnmixedAsingledatabaseresultobjectortheresultofthecallbackfunction.@throws\DatabaseException
Definition at line 192 of file Database.php.
Elgg\Database::getLink | ( | $type | ) |
Gets (if required, also creates) a database link resource.
The database link resources are created by Elgg\Database::setupConnections(),whichiscalledifnolinksexist.@paramstring$typeThetypeoflinkwewant:"read","write"or"readwrite".@returnresourceDatabaselink@throws\DatabaseException\xrefitemtodo13.
Definition at line 98 of file Database.php.
Elgg\Database::getQueryCount | ( | ) |
Get the number of queries made to the database.
Definition at line 606 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? |
Definition at line 319 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 661 of file Database.php.
Elgg\Database::getTablePrefix | ( | ) |
Elgg\Database::insertData | ( | $query | ) |
Insert a row into the database.
mixed | $query | The query to execute. |
Definition at line 207 of file Database.php.
|
protected |
Elgg\Database::registerDelayedQuery | ( | $query, | |
$type, | |||
$handler = "" |
|||
) |
Queue a query for execution upon shutdown.
You can specify a handler function if you care about the result. This function will accept the raw result from mysql_query().
string | $query | The query to execute |
string | $type | The query type ('read' or 'write') |
string | $handler | A callback function to pass the results array to |
Definition at line 487 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 436 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 626 of file Database.php.
Elgg\Database::sanitizeString | ( | $value | ) |
Sanitizes a string for use in a query.
string | $value | Value to escape |
Definition at line 644 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 118 of file Database.php.
Elgg\Database::updateData | ( | $query, | |
$getNumRows = false |
|||
) |
Update the database.
string | $query | The query to run. |
bool | $getNumRows | Return the number of rows affected (default: false) |
Definition at line 233 of file Database.php.
global Elgg\Database::$ELGG_PLUGINS_PROVIDES_CACHE |
Definition at line 10 of file Plugins.php.
global Elgg\Database::$SUBTYPE_CACHE |
Cache subtypes and related class names.
array|null $SUBTYPE_CACHE array once populated from DB, initially null private
Definition at line 10 of file SubtypeTable.php.
Elgg\Database::$SUBTYPE_CACHE = null |
Definition at line 11 of file SubtypeTable.php.
global Elgg\Database::$USERNAME_TO_GUID_MAP_CACHE |
Definition at line 9 of file UsersTable.php.
Elgg\Database::$USERNAME_TO_GUID_MAP_CACHE = array() |
Definition at line 10 of file UsersTable.php.