Elgg  Version 2.3
Namespaces | Functions | Variables
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, $callback=null, array $params=[])
 Queue a query for running during shutdown that writes to the database. More...
 
 execute_delayed_read_query ($query, $callback=null, array $params=[])
 Queue a query for running during shutdown that reads from the database. More...
 
 get_data ($query, $callback=null, array $params=[])
 Retrieve rows from the database. More...
 
 get_data_row ($query, $callback=null, array $params=[])
 Retrieve a single row from the database. More...
 
 insert_data ($query, array $params=[])
 Insert a row into the database. More...
 
 update_data ($query, array $params=[], $get_num_rows=false)
 Update a row in the database. More...
 
 delete_data ($query, array $params=[])
 Remove a row from the database. More...
 
 run_sql_script ($scriptlocation)
 Runs a full database script from disk. More...
 
 sanitize_string ($string)
 Sanitizes a string for use in a query. More...
 
 sanitise_string ($string)
 Alias of sanitize_string. More...
 
 sanitize_int ($int, $signed=true)
 Sanitizes an integer for database use. More...
 
 sanitise_int ($int, $signed=true)
 Alias of sanitize_int. More...
 
 elgg_enable_query_cache ()
 Enable the MySQL query cache. More...
 
 elgg_disable_query_cache ()
 Disable the MySQL query cache. 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_test ($hook, $type, $value)
 Runs unit tests for the database. More...
 
 _elgg_db_init ()
 Registers shutdown functions for database profiling and delayed queries. More...
 

Variables

return function (\Elgg\EventsService $events,\Elgg\HooksRegistrationService $hooks)
 

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
private

Definition at line 250 of file database.php.

_elgg_db_init ( )

Registers shutdown functions for database profiling and delayed queries.

private

Definition at line 284 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 228 of file database.php.

_elgg_db_run_delayed_queries ( )

Execute any delayed queries upon shutdown.

Returns
void private

Definition at line 260 of file database.php.

_elgg_db_test (   $hook,
  $type,
  $value 
)

Runs unit tests for the database.

Parameters
string$hookunit_test
string$typesystem
array$valueArray of tests
Returns
array private

Definition at line 274 of file database.php.

delete_data (   $query,
array  $params = [] 
)

Remove a row from the database.

Note
Altering the DB invalidates all queries in the query cache
Parameters
string$queryThe SQL query to run
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
int|false The number of affected rows or false on failure

Definition at line 116 of file database.php.

elgg_disable_query_cache ( )

Disable the MySQL query cache.

Note
Elgg already manages the query cache sensibly, so you probably don't need to use this.
Returns
void
Since
2.0.0

Definition at line 218 of file database.php.

elgg_enable_query_cache ( )

Enable the MySQL query cache.

Returns
void
Since
2.0.0

Definition at line 205 of file database.php.

execute_delayed_read_query (   $query,
  $callback = null,
array  $params = [] 
)

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

Parameters
string$queryThe query to execute
callable$callbackThe optional callback for processing. The callback will receive a object
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
boolean

Definition at line 35 of file database.php.

execute_delayed_write_query (   $query,
  $callback = null,
array  $params = [] 
)

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

Parameters
string$queryThe query to execute
callable$callbackThe optional callback for processing. The callback will receive a object
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
boolean

Definition at line 21 of file database.php.

get_data (   $query,
  $callback = null,
array  $params = [] 
)

Retrieve rows from the database.

Queries are executed with Elgg\Database::getResultsandresultsareretrievedwith@link\PDO::fetchObject().Ifacallbackfunction$callbackisdefined,eachrowwillbepassedasthesingleargumentto$callback.Ifnocallbackfunctionisdefined,theentireresultsetisreturnedasanarray.@paramstring$queryThequerybeingpassed.@paramcallable$callbackOptionally,thenameofafunctiontocallbacktooneachrow@paramarray$paramsQueryparams.E.g.[1,'steve']or[':id'=>1,':name'=>'steve']@returnarrayAnarrayofdatabaseresultobjectsorcallbackfunctionresults.Ifthequeryreturnednothing,anemptyarray.

Definition at line 55 of file database.php.

get_data_row (   $query,
  $callback = null,
array  $params = [] 
)

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
string$queryThe query to execute.
callable$callbackA callback function to apply to the row
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Returns
mixed A single database result object or the result of the callback function.

Definition at line 72 of file database.php.

insert_data (   $query,
array  $params = [] 
)

Insert a row into the database.

Note
Altering the DB invalidates all queries in the query cache
Parameters
string$queryThe query to execute.
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
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 87 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 140 of file database.php.

sanitise_int (   $int,
  $signed = true 
)

Alias of sanitize_int.

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

Definition at line 194 of file database.php.

sanitise_string (   $string)

Alias of sanitize_string.

See also
Elgg::sanitizeString
Parameters
string$stringThe string to sanitize
Returns
string

Definition at line 166 of file database.php.

sanitize_int (   $int,
  $signed = true 
)

Sanitizes an integer for database use.

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

Definition at line 180 of file database.php.

sanitize_string (   $string)

Sanitizes a string for use in a query.

See also
Elgg::sanitizeString
Parameters
string$stringThe string to sanitize
Returns
string

Definition at line 153 of file database.php.

update_data (   $query,
array  $params = [],
  $get_num_rows = false 
)

Update a row in the database.

Note
Altering the DB invalidates all queries in the query cache
Parameters
string$queryThe query to run.
array$paramsQuery params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
bool$get_num_rowsReturn the number of rows affected (default: false).
Returns
bool

Definition at line 102 of file database.php.

Variable Documentation

Definition at line 290 of file database.php.