Elgg
Version 1.9
|
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... | |
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 13 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 74 of file Database.php.
Elgg_Database::assertInstalled | ( | ) |
Test that the Elgg database is installed.
InstallationException |
Definition at line 580 of file Database.php.
Elgg_Database::deleteData | ( | $query | ) |
Delete data from the database.
string | $query | The SQL query to run |
DatabaseException |
Definition at line 260 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 558 of file Database.php.
Elgg_Database::enableQueryCache | ( | ) |
Enable the query cache.
This does not take precedence over the Elgg_Database_Config setting.
Definition at line 543 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". |
DatabaseException |
Definition at line 137 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 511 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 |
DatabaseException |
Definition at line 389 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 288 of file Database.php.
Elgg_Database::getData | ( | $query, | |
$callback = '' |
|||
) |
Retrieve rows from the database.
Queries are executed with Elgg_Database::executeQuery() and results are retrieved with mysql_fetch_object(). 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.
mixed | $query | The query being passed. |
string | $callback | Optionally, the name of a function to call back to on each row |
DatabaseException |
Definition at line 173 of file Database.php.
Elgg_Database::getDataRow | ( | $query, | |
$callback = '' |
|||
) |
Retrieve a single row from the database.
Similar to Elgg_Database::getData() 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.
mixed | $query | The query to execute. |
string | $callback | A callback function |
DatabaseException |
Definition at line 190 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(), which is called if no links exist.
string | $type | The type of link we want: "read", "write" or "readwrite". |
DatabaseException |
Definition at line 96 of file Database.php.
Elgg_Database::getQueryCount | ( | ) |
Get the number of queries made to the database.
Definition at line 604 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? |
DatabaseException |
Definition at line 317 of file Database.php.
Elgg_Database::getTablePrefix | ( | ) |
Elgg_Database::insertData | ( | $query | ) |
Insert a row into the database.
mixed | $query | The query to execute. |
DatabaseException |
Definition at line 205 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 485 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 |
DatabaseException |
Definition at line 434 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 624 of file Database.php.
Elgg_Database::sanitizeString | ( | $value | ) |
Sanitizes a string for use in a query.
string | $value | Value to escape |
Definition at line 642 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.
DatabaseException |
Definition at line 116 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) |
DatabaseException |
Definition at line 231 of file Database.php.