engine/lib/database.php File Reference

(r6838/r6794)

Go to the source code of this file.

Packages

package  Elgg
 

Elgg CSS file.


Functions

 establish_db_link ($dblinkname="readwrite")
 Connect to the database server and use the Elgg database for a particular database link.
 setup_db_connections ()
 Establish all database connections.
 db_profiling_shutdown_hook ()
 Shutdown hook to display profiling information about db (debug mode).
 db_delayedexecution_shutdown_hook ()
 Execute any delayed queries.
 init_db ($event, $object_type, $object=null)
 Alias to setup_db_connections, for use in the event handler.
 get_db_link ($dblinktype)
 Gets the appropriate db link for the operation mode requested.
 explain_query ($query, $link)
 Explain a given query, useful for debug.
 execute_query ($query, $dblink)
 Execute a query.
 execute_delayed_query ($query, $dblink, $handler="")
 Queue a query for execution after all output has been sent to the user.
 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="")
 Use this function to get data from the database.
 get_data_row ($query, $callback="")
 Use this function to get a single data row from the database.
 insert_data ($query)
 Use this function to insert database data; returns id or false.
 update_data ($query)
 Update database data.
 delete_data ($query)
 Use this function to delete data.
 get_db_tables ()
 Get the tables currently installed in the Elgg database.
 optimize_table ($table)
 Run an optimize query on a mysql tables.
 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.
 db_upgrade ($version, $fromdir="", $quiet=FALSE)
 Upgrade the database schema in an ordered sequence.
 db_check_version ()
 This function, called by validate_platform(), will check whether the installed version of MySQL meets the minimum required.
 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)
 Sanitises an integer for database use.
 sanitize_int ($int)
 Wrapper function for alternate English spelling.

Variables

 $DB_QUERY_CACHE = array()
 $DB_DELAYED_QUERIES = array()

Function Documentation

db_check_version (  ) 

This function, called by validate_platform(), will check whether the installed version of MySQL meets the minimum required.

Todo:
If multiple dbs are supported check which db is supported and use the appropriate code to validate the appropriate version.
Returns:
bool

Definition at line 585 of file database.php.

References $version.

Referenced by validate_platform().

db_delayedexecution_shutdown_hook (  ) 

Execute any delayed queries.

Definition at line 108 of file database.php.

References $CONFIG, $DB_DELAYED_QUERIES, $e, $result, elgg_log(), and execute_query().

db_profiling_shutdown_hook (  ) 

Shutdown hook to display profiling information about db (debug mode).

Definition at line 98 of file database.php.

References elgg_log().

db_upgrade ( version,
fromdir = "",
quiet = FALSE 
)

Upgrade the database schema in an ordered sequence.

Makes use of schema upgrade files

This is a about as core as it comes, so don't start running this from your plugins!

Parameters:
int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example)
string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/)
bool $quiet If true, will suppress all error messages. Don't use this.
Returns:
bool

Definition at line 526 of file database.php.

References $CONFIG, $e, $version, is_db_installed(), is_installed(), and run_sql_script().

Referenced by version_upgrade().

delete_data ( query  ) 
establish_db_link ( dblinkname = "readwrite"  ) 

Connect to the database server and use the Elgg database for a particular database link.

Parameters:
string $dblinkname Default "readwrite"; you can change this to set up additional global database links, eg "read" and "write"

Definition at line 22 of file database.php.

References $CONFIG, $DB_QUERY_CACHE, $dbhost, $dbname, $dbuser, and elgg_echo().

Referenced by setup_db_connections().

execute_delayed_query ( query,
dblink,
handler = "" 
)

Queue a query for execution after all output has been sent to the user.

You can specify a handler function if you care about the result. This function will accept the raw result from mysql_query();

Parameters:
string $query The query to execute
resource $dblink The database link to use
string $handler The handler

Definition at line 204 of file database.php.

References $DB_DELAYED_QUERIES, $handler, and $query.

Referenced by execute_delayed_read_query(), and execute_delayed_write_query().

execute_delayed_read_query ( query,
handler = "" 
)

Read wrapper for execute_delayed_query().

Parameters:
string $query The query to execute
string $handler The handler if you care about the result.

Definition at line 238 of file database.php.

References $handler, $query, execute_delayed_query(), and get_db_link().

execute_delayed_write_query ( query,
handler = "" 
)

Write wrapper for execute_delayed_query().

Parameters:
string $query The query to execute
string $handler The handler if you care about the result.

Definition at line 228 of file database.php.

References $handler, $query, execute_delayed_query(), and get_db_link().

Referenced by elgg_geocode_location().

execute_query ( query,
dblink 
)

Execute a query.

Parameters:
string $query The query
link $dblink the DB link
Returns:
Returns a the result of mysql_query

Definition at line 177 of file database.php.

References $CONFIG, $DB_QUERY_CACHE, $query, and $result.

Referenced by db_delayedexecution_shutdown_hook(), delete_data(), explain_query(), get_data(), get_data_row(), insert_data(), and update_data().

explain_query ( query,
link 
)

Explain a given query, useful for debug.

Definition at line 162 of file database.php.

References $link, $query, $result, and execute_query().

get_data ( query,
callback = "" 
)

Use this function to get data from the database.

Parameters:
mixed $query The query being passed.
string $call Optionally, the name of a function to call back to on each row (which takes $row as a single parameter)
Returns:
array An array of database result objects

Definition at line 248 of file database.php.

References $callback, $CONFIG, $DB_QUERY_CACHE, $query, $result, elgg_log(), execute_query(), and get_db_link().

Referenced by __get_entities_from_annotations_calculate_x(), clear_annotations_by_owner(), clear_metadata_by_owner(), datalist_get(), delete_entity(), delete_orphaned_metastrings(), disable_entity(), elgg_get_entities(), elgg_get_tags(), elgg_is_admin_user(), find_active_users(), find_metadata(), get_access_array(), get_activity_stream_data(), get_all_config(), get_all_private_settings(), get_annotations(), get_db_tables(), get_entities_by_relationship_count(), get_entities_from_metadata_groups(), get_entities_from_metadata_groups_multi(), get_entities_from_private_setting(), get_entities_from_private_setting_multi(), get_entities_in_area(), get_entity_dates(), get_entity_relationships(), get_entity_statistics(), get_members_of_access_collection(), get_metadata_byname(), get_metadata_for_entity(), get_metastring_id(), get_notable_entities(), get_notable_entities_from_metadata(), get_noteable_entities_from_relationship(), get_objects_in_group(), get_river_items(), get_system_log(), get_user_access_collections(), get_user_by_email(), get_user_tokens(), get_write_access_array(), has_access_to_entity(), input_livesearch_page_handler(), remove_metadata(), search_comments_hook(), search_for_group(), search_for_object(), search_for_site(), and search_for_user().

get_data_row ( query,
callback = "" 
)

Use this function to get a single data row from the database.

Parameters:
mixed $query The query to run.
Returns:
object A single database result object

Definition at line 302 of file database.php.

References $callback, $CONFIG, $DB_QUERY_CACHE, $query, $result, elgg_log(), execute_query(), and get_db_link().

Referenced by __elgg_session_read(), __get_annotations_calculate_x(), __get_entities_from_annotations_calculate_x(), check_entity_relationship(), create_group_entity(), create_metadata(), create_object_entity(), create_site_entity(), create_user_entity(), elgg_geocode_location(), elgg_get_entities(), ElggCoreUserTest.fetchUser(), get_access_collection(), get_annotation(), get_api_user(), get_config(), get_entities_by_relationship_count(), get_entities_from_metadata_groups(), get_entities_from_metadata_groups_multi(), get_entities_from_private_setting(), get_entities_from_private_setting_multi(), get_entities_in_area(), get_entity_as_row(), ElggCoreObjectTest.get_entity_row(), get_entity_statistics(), get_group_entity_as_row(), get_log_entry(), get_metadata(), get_metastring(), get_notable_entities(), get_notable_entities_from_metadata(), get_noteable_entities_from_relationship(), get_number_users(), get_object_entity_as_row(), ElggCoreObjectTest.get_object_row(), get_objects_in_group(), get_private_setting(), get_relationship(), get_site_by_url(), get_site_entity_as_row(), get_subtype_class(), get_subtype_class_from_id(), get_subtype_from_id(), get_subtype_id(), get_system_log(), get_user_by_code(), get_user_by_username(), get_user_entity_as_row(), ElggHMACCache.load(), search_for_group(), search_for_object(), search_for_site(), search_for_user(), ElggCoreEntityTest.testElggEntityDisableAndEnable(), and validate_user_token().

get_db_error ( dblink  ) 

Get the last database error for a particular database link.

Parameters:
database link $dblink
Returns:
string Database error message

Definition at line 474 of file database.php.

get_db_link ( dblinktype  ) 

Gets the appropriate db link for the operation mode requested.

Parameters:
string $dblinktype The type of link we want - "read", "write" or "readwrite" (the default)
Returns:
object Database link

Definition at line 145 of file database.php.

References setup_db_connections().

Referenced by delete_data(), execute_delayed_read_query(), execute_delayed_write_query(), get_data(), get_data_row(), insert_data(), is_db_installed(), search_init(), and update_data().

get_db_tables (  ) 

Get the tables currently installed in the Elgg database.

Returns:
array List of tables

Definition at line 427 of file database.php.

References $CONFIG, $result, and get_data().

Referenced by garbagecollector_cron().

init_db ( event,
object_type,
object = null 
)

Alias to setup_db_connections, for use in the event handler.

Parameters:
string $event The event type
string $object_type The object type
mixed $object Used for nothing in this context

Definition at line 132 of file database.php.

insert_data ( query  ) 
optimize_table ( table  ) 

Run an optimize query on a mysql tables.

Useful for executing after major data changes.

Definition at line 463 of file database.php.

References sanitise_string(), and update_data().

Referenced by garbagecollector_cron().

run_sql_script ( scriptlocation  ) 

Runs a full database script from disk.

$CONFIG

Parameters:
string $scriptlocation The full path to the script

Definition at line 484 of file database.php.

References $CONFIG, $e, $error, $errors, $result, $statement, elgg_echo(), and update_data().

Referenced by db_upgrade().

sanitise_int ( int  ) 
sanitise_string ( string  ) 

Sanitise a string for database use.

Parameters:
string $string The string to sanitise
Returns:
string Sanitised string

Definition at line 615 of file database.php.

References $string.

Referenced by WhereSetQueryComponent.__construct(), WhereStaticQueryComponent.__construct(), WhereQueryComponent.__construct(), SetQueryComponent.__construct(), JoinQueryComponent.__construct(), AccessControlQueryComponent.__construct(), TableQueryComponent.__construct(), OrderQueryComponent.__construct(), SelectFieldQueryComponent.__construct(), __elgg_session_destroy(), __elgg_session_read(), __elgg_session_write(), __get_annotations_calculate_x(), __get_entities_from_annotations_calculate_x(), add_entity_relationship(), add_metastring(), add_subtype(), add_to_river(), add_uuid_to_guid(), ban_user(), callpath_gatekeeper(), check_entity_relationship(), create_access_collection(), create_annotation(), create_entity(), create_group_entity(), create_metadata(), create_object_entity(), create_site_entity(), create_user_entity(), datalist_get(), datalist_set(), ElggHMACCache.delete(), disable_entity(), disable_plugin(), elgg_geocode_location(), elgg_get_entities(), elgg_get_entity_metadata_where_sql(), elgg_get_entity_relationship_where_sql(), elgg_get_tags(), enable_plugin(), find_metadata(), find_plugin_settings(), find_plugin_usersettings(), get_access_sql_suffix(), get_activity_stream_data(), get_annotations(), get_api_user(), get_config(), get_entities_by_relationship_count(), get_entities_from_access_id(), get_entities_from_metadata_groups(), get_entities_from_metadata_groups_multi(), get_entities_from_private_setting(), get_entities_from_private_setting_multi(), get_entities_in_area(), get_entity_dates(), get_entity_from_uuid(), get_entity_icon_url(), get_language_completeness(), get_metastring_id(), get_notable_entities(), get_notable_entities_from_metadata(), get_noteable_entities_from_relationship(), get_objects_in_group(), get_plugin_usersetting(), get_private_setting(), get_river_items(), get_site_by_url(), get_site_collections(), get_site_objects(), get_subtype_class(), get_subtype_id(), get_system_log(), get_user_by_code(), get_user_by_email(), get_user_by_username(), input_livesearch_page_handler(), ElggHMACCache.load(), map_api_hash(), optimize_table(), remove_entity_relationship(), remove_entity_relationships(), remove_metadata(), remove_private_setting(), remove_user_token(), sanitise_string_special(), sanitize_string(), ElggHMACCache.save(), search_comments_hook(), search_for_group(), search_for_object(), search_for_site(), search_for_user(), search_get_where_sql(), search_groups_hook(), search_tags_hook(), search_users_hook(), send_admin_message(), serialise_parameters(), set_config(), set_plugin_usersetting(), set_private_setting(), set_user_notification_setting(), ElggEntity.setIcon(), ElggEntity.setLatLong(), ElggEntity.setLocation(), SimpleQuery.simpleOrder(), SimpleQuery.simpleQueryType(), system_log(), unset_config(), update_annotation(), update_metadata(), uservalidationbyemail_page_handler(), validate_user_token(), and volatile_data_export_plugin_hook().

sanitise_string_special ( string,
extra_escapeable = '' 
)

Sanitise a string for database use, but with the option of escaping extra characters.

Definition at line 599 of file database.php.

References $n, $string, and sanitise_string().

sanitize_int ( int  ) 

Wrapper function for alternate English spelling.

Parameters:
int $int
Returns:
int Sanitised integer sanitise_string

Definition at line 649 of file database.php.

sanitize_string ( string  ) 

Wrapper function for alternate English spelling.

Parameters:
string $string The string to sanitise
Returns:
string Sanitised string sanitise_string

Definition at line 628 of file database.php.

References $string, and sanitise_string().

setup_db_connections (  ) 

Establish all 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 83 of file database.php.

References $CONFIG, and establish_db_link().

Referenced by get_db_link().

update_data ( query  ) 

Variable Documentation

$DB_DELAYED_QUERIES = array()

Definition at line 15 of file database.php.

Referenced by db_delayedexecution_shutdown_hook(), and execute_delayed_query().

$DB_QUERY_CACHE = array()
 All Classes Namespaces Files Functions Variables Enumerations
Generated on Thu Sep 2 00:13:01 2010 for Elgg by  doxygen 1.6.3