Elgg  Version 1.9
Namespaces | Functions
database.php File Reference

Go to the source code of this file.

Namespaces

 Elgg\Core
 Activate a plugin or plugins.
 

Functions

 execute_delayed_write_query ($query, $handler="")
 Queue a query for running during shutdown that writes to the database. More...
 
 execute_delayed_read_query ($query, $handler="")
 Queue a query for running during shutdown that reads from the database. More...
 
 get_data ($query, $callback="")
 Retrieve rows from the database. More...
 
 get_data_row ($query, $callback="")
 Retrieve a single row from the database. More...
 
 insert_data ($query)
 Insert a row into the database. More...
 
 update_data ($query)
 Update a row in the database. More...
 
 delete_data ($query)
 Remove a row from the database. More...
 
 run_sql_script ($scriptlocation)
 Runs a full database script from disk. More...
 
 sanitize_string ($string)
 Sanitize a string for database use. More...
 
 sanitise_string ($string)
 Wrapper function for alternate English spelling (. More...
 
 sanitize_int ($int, $signed=true)
 Sanitizes an integer for database use. More...
 
 sanitise_int ($int, $signed=true)
 Sanitizes an integer for database use. More...
 
 _elgg_db_log_profiling_data ()
 Log db profiling information at NOTICE debug level upon shutdown. More...
 
 _elgg_db_get_query_counter ()
 Get a new query counter that will begin counting from 0. More...
 
 _elgg_db_run_delayed_queries ()
 Execute any delayed queries upon shutdown. More...
 
 _elgg_db_init ()
 Registers shutdown functions for database profiling and delayed queries. More...
 

Function Documentation

_elgg_db_get_query_counter ( )

Get a new query counter that will begin counting from 0.

For profiling isolated sections of code.

$counter = _elgg_db_get_query_counter();

... code to profile

$counter->setDeltaHeader();

Returns
Elgg_Database_QueryCounter private

Definition at line 205 of file database.php.

_elgg_db_init ( )

Registers shutdown functions for database profiling and delayed queries.

private

Definition at line 224 of file database.php.

_elgg_db_log_profiling_data ( )

Log db profiling information at NOTICE debug level upon shutdown.

Returns
void private

Definition at line 183 of file database.php.

_elgg_db_run_delayed_queries ( )

Execute any delayed queries upon shutdown.

Returns
void private

Definition at line 215 of file database.php.

delete_data (   $query)

Remove a row from the database.

Note
Altering the DB invalidates all queries in $DB_QUERY_CACHE.
Parameters
string$queryThe SQL query to run
Returns
int|false The number of affected rows or false on failure

Definition at line 106 of file database.php.

execute_delayed_read_query (   $query,
  $handler = "" 
)

Queue a query for running during shutdown that reads from the database.

Parameters
string$queryThe query to execute
string$handlerThe optional handler for processing the result
Returns
boolean

Definition at line 31 of file database.php.

execute_delayed_write_query (   $query,
  $handler = "" 
)

Queue a query for running during shutdown that writes to the database.

Parameters
string$queryThe query to execute
string$handlerThe optional handler for processing the result
Returns
boolean

Definition at line 19 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.

Parameters
mixed$queryThe query being passed.
string$callbackOptionally, the name of a function to call back to on each row
Returns
array An array of database result objects or callback function results. If the query returned nothing, an empty array.

Definition at line 50 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.

Parameters
mixed$queryThe query to execute.
string$callbackA callback function
Returns
mixed A single database result object or the result of the callback function.

Definition at line 66 of file database.php.

insert_data (   $query)

Insert a row into the database.

Note
Altering the DB invalidates all queries in $DB_QUERY_CACHE.
Parameters
mixed$queryThe query to execute.
Returns
int|false The database id of the inserted row if a AUTO_INCREMENT field is defined, 0 if not, and false on failure.

Definition at line 80 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.

Warning
Errors do not halt execution of the script. If a line generates an error, the error message is saved and the next line is executed. After the file is run, any errors are displayed as a DatabaseException
Parameters
string$scriptlocationThe full path to the script
Returns
void
Exceptions
DatabaseException

Definition at line 130 of file database.php.

sanitise_int (   $int,
  $signed = true 
)

Sanitizes an integer for database use.

Wrapper function for alternate English spelling (

See also
sanitize_int)
Parameters
int$intValue to be sanitized
bool$signedWhether negative values should be allowed (true)
Returns
int

Definition at line 173 of file database.php.

sanitise_string (   $string)

Wrapper function for alternate English spelling (.

See also
sanitize_string)
Parameters
string$stringThe string to sanitize
Returns
string

Definition at line 150 of file database.php.

sanitize_int (   $int,
  $signed = true 
)

Sanitizes an integer for database use.

Parameters
int$intValue to be sanitized
bool$signedWhether negative values should be allowed (true)
Returns
int

Definition at line 161 of file database.php.

sanitize_string (   $string)

Sanitize a string for database use.

Parameters
string$stringThe string to sanitize
Returns
string

Definition at line 140 of file database.php.

update_data (   $query)

Update a row in the database.

Note
Altering the DB invalidates all queries in $DB_QUERY_CACHE.
Parameters
string$queryThe query to run.
Returns
bool

Definition at line 93 of file database.php.