Go to the source code of this file.
Namespaces | |
| namespace | Elgg::Core |
Activate a plugin or plugins. | |
Functions | |
| establish_db_link ($dblinkname="readwrite") | |
| Establish a connection to the database servser. | |
| setup_db_connections () | |
| Establish database connections. | |
| db_profiling_shutdown_hook () | |
| Display profiling information about db at NOTICE debug level upon shutdown. | |
| db_delayedexecution_shutdown_hook () | |
| Execute any delayed queries upon shutdown. | |
| get_db_link ($dblinktype) | |
| Returns (if required, also creates) a database link resource. | |
| explain_query ($query, $link) | |
| Execute an EXPLAIN for $query. | |
| execute_query ($query, $dblink) | |
| Execute a query. | |
| execute_delayed_query ($query, $dblink, $handler="") | |
| Queue a query for execution upon shutdown. | |
| execute_delayed_write_query ($query, $handler="") | |
| Write wrapper for execute_delayed_query(). | |
| execute_delayed_read_query ($query, $handler="") | |
| Read wrapper for execute_delayed_query(). | |
| get_data ($query, $callback="") | |
| Retrieve rows from the database. | |
| get_data_row ($query, $callback="") | |
| Retrieve a single row from the database. | |
| elgg_query_runner ($query, $callback=null, $single=false) | |
| Handles returning data from a query, running it through a callback function, and caching the results. | |
| insert_data ($query) | |
| Insert a row into the database. | |
| update_data ($query) | |
| Update the database. | |
| delete_data ($query) | |
| Remove data from the database. | |
| _elgg_invalidate_query_cache () | |
| Invalidate the query cache. | |
| optimize_table ($table) | |
| Optimise a table. | |
| get_db_error ($dblink) | |
| Get the last database error for a particular database link. | |
| run_sql_script ($scriptlocation) | |
| Runs a full database script from disk. | |
| elgg_format_query ($query) | |
| Format a query string for logging. | |
| sanitise_string_special ($string, $extra_escapeable= '') | |
| Sanitise a string for database use, but with the option of escaping extra characters. | |
| sanitise_string ($string) | |
| Sanitise a string for database use. | |
| sanitize_string ($string) | |
| Wrapper function for alternate English spelling. | |
| sanitise_int ($int, $signed=true) | |
| Sanitises an integer for database use. | |
| sanitize_int ($int, $signed=true) | |
| Sanitizes an integer for database use. | |
| init_db () | |
| Registers shutdown functions for database profiling and delayed queries. | |
Variables | |
| global | $DB_QUERY_CACHE = null |
| Query cache for all queries. | |
| global | $DB_DELAYED_QUERIES = array() |
| Queries to be executed upon shutdown. | |
| global | $dblink = array() |
| Database connection resources. | |
| global | $dbcalls = 0 |
| Database call count. | |
| _elgg_invalidate_query_cache | ( | ) |
| db_delayedexecution_shutdown_hook | ( | ) |
Execute any delayed queries upon shutdown.
Definition at line 175 of file database.php.
| db_profiling_shutdown_hook | ( | ) |
Display profiling information about db at NOTICE debug level upon shutdown.
Definition at line 162 of file database.php.
| delete_data | ( | $ | query | ) |
Remove data from the database.
| string | $query The SQL query to run |
Definition at line 510 of file database.php.
| elgg_format_query | ( | $ | query | ) |
Format a query string for logging.
| string | $query Query string |
Definition at line 676 of file database.php.
| elgg_query_runner | ( | $ | query, | |
| $ | callback = null, |
|||
| $ | single = false | |||
| ) |
Handles returning data from a query, running it through a callback function, and caching the results.
This is for R queries (from CRUD).
private
| string | $query The query to execute | |
| string | $callback An optional callback function to run on each row | |
| bool | $single Return only a single result? |
Definition at line 397 of file database.php.
| establish_db_link | ( | $ | dblinkname = "readwrite" |
) |
Establish a connection to the database servser.
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. eg "read", "write", or "readwrite". |
| DatabaseException | private |
Definition at line 85 of file database.php.
| execute_delayed_query | ( | $ | query, | |
| $ | dblink, | |||
| $ | 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 | |
| resource|string | $dblink The database link to use or the link type (read | write) | |
| string | $handler A callback function to pass the results array to |
Definition at line 293 of file database.php.
| execute_delayed_read_query | ( | $ | query, | |
| $ | handler = "" | |||
| ) |
Read wrapper for execute_delayed_query().
| string | $query The query to execute | |
| string | $handler The handler if you care about the result. |
Definition at line 341 of file database.php.
| execute_delayed_write_query | ( | $ | query, | |
| $ | handler = "" | |||
| ) |
Write wrapper for execute_delayed_query().
| string | $query The query to execute | |
| string | $handler The handler if you care about the result. |
Definition at line 326 of file database.php.
| execute_query | ( | $ | query, | |
| $ | dblink | |||
| ) |
Execute a query.
$query is executed via mysql_query(). If there is an SQL error, a DatabaseException is thrown.
Definition at line 258 of file database.php.
| explain_query | ( | $ | query, | |
| $ | link | |||
| ) |
Execute an EXPLAIN for $query.
| string | $query The query to explain | |
| mixed | $link The database link resource to user. |
Definition at line 234 of file database.php.
| get_data | ( | $ | query, | |
| $ | callback = "" | |||
| ) |
Retrieve rows from the database.
Queries are executed with execute_query() and results are retrieved with mysql_fetch_object(). If a callback function $callback is defined, each row will be passed as the 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 |
Definition at line 361 of file database.php.
| get_data_row | ( | $ | query, | |
| $ | callback = "" | |||
| ) |
Retrieve a single row from the database.
Similar to get_data() 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 |
Definition at line 378 of file database.php.
| get_db_error | ( | $ | dblink | ) |
Get the last database error for a particular database link.
| resource | $dblink The DB link |
Definition at line 606 of file database.php.
| get_db_link | ( | $ | dblinktype | ) |
Returns (if required, also creates) a database link resource.
Database link resources are stored in the $dblink global. These resources are created by setup_db_connections(), which is called if no links exist.
| string | $dblinktype The type of link we want: "read", "write" or "readwrite". |
Definition at line 212 of file database.php.
| init_db | ( | ) |
Registers shutdown functions for database profiling and delayed queries.
private
Definition at line 759 of file database.php.
| insert_data | ( | $ | query | ) |
Insert a row into the database.
| mixed | $query The query to execute. |
Definition at line 460 of file database.php.
| optimize_table | ( | $ | table | ) |
Optimise a table.
Executes an OPTIMIZE TABLE query on $table. Useful after large DB changes.
| string | $table The name of the table to optimise |
Definition at line 593 of file database.php.
| run_sql_script | ( | $ | 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
) with only one statement per line.
The special string 'prefix_' is replaced with the database prefix as defined in ->dbprefix.
| string | $scriptlocation The full path to the script |
| DatabaseException | private |
Definition at line 631 of file database.php.
| sanitise_int | ( | $ | int, | |
| $ | signed = true | |||
| ) |
Sanitises an integer for database use.
| int | $int Value to be sanitized | |
| bool | $signed Whether negative values should be allowed (true) |
Definition at line 730 of file database.php.
| sanitise_string | ( | $ | string | ) |
Sanitise a string for database use.
| string | $string The string to sanitise |
Definition at line 706 of file database.php.
| sanitise_string_special | ( | $ | string, | |
| $ | extra_escapeable = '' | |||
| ) |
Sanitise a string for database use, but with the option of escaping extra characters.
| string | $string The string to sanitise | |
| string | $extra_escapeable Extra characters to escape with '\' |
Definition at line 689 of file database.php.
| sanitize_int | ( | $ | int, | |
| $ | signed = true | |||
| ) |
Sanitizes an integer for database use.
Wrapper function for alternate English spelling (
| int | $int Value to be sanitized | |
| bool | $signed Whether negative values should be allowed (true) |
Definition at line 750 of file database.php.
| sanitize_string | ( | $ | string | ) |
Wrapper function for alternate English spelling.
| string | $string The string to sanitise |
Definition at line 719 of file database.php.
| setup_db_connections | ( | ) |
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 145 of file database.php.
| update_data | ( | $ | query | ) |
Update the database.
| string | $query The query to run. |
Definition at line 485 of file database.php.
| $DB_DELAYED_QUERIES = array() |
Queries to be executed upon shutdown.
These queries are saved to an array and executed using a function registered by register_shutdown_function().
Queries are saved as an array in the format: $DB_DELAYED_QUERIES[] = array( 'q' => str $query, 'l' => resource $dblink, 'h' => str $handler // a callback function );
array $DB_DELAYED_QUERIES private
Definition at line 47 of file database.php.
| $DB_QUERY_CACHE = null |
Query cache for all queries.
Each query and its results are stored in this cache as: $DB_QUERY_CACHE[query hash] => array(result1, result2, ... resultN)
ElggLRUCache|null $DB_QUERY_CACHE private
Definition at line 26 of file database.php.
| $dbcalls = 0 |
Database call count.
Each call to the database increments this counter.
integer $dbcalls private
Definition at line 70 of file database.php.
| $dblink = array() |
Database connection resources.
Each database link created with establish_db_link($name) is stored in $dblink as $dblink[$name] => resource. Use get_db_link($name) to retrieve it.
resource[] $dblink private
Definition at line 59 of file database.php.
1.6.3