Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 400 and 402]

(no description)

File Size: 165 lines (6 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: database  - X-Ref

Helper functions for DB manipulations

generate_alias()   X-Ref
Generates unique table/column alias that must be used in generated SQL

return: string

generate_aliases(int $count)   X-Ref
Generate multiple unique table/column aliases, see {@see generate_alias} for info

param: int $count
return: string[]

generate_param_name()   X-Ref
Generates unique parameter name that must be used in generated SQL

return: string

generate_param_names(int $count)   X-Ref
Generate multiple unique parameter names, see {@see generate_param_name} for info

param: int $count
return: string[]

validate_params(array $params)   X-Ref
Validate that parameter names were generated using {@see generate_param_name}.

param: array $params
return: bool

sql_replace_parameter_names(string $sql, array $params, callable $callback)   X-Ref
Replace parameter names within given SQL expression, allowing caller to specify callback to handle their replacement
primarily to ensure uniqueness when the expression is to be used as part of a larger query

param: string $sql
param: array $params
param: callable $callback Method that takes a single string parameter, and returns another string
return: string

sql_group_concat_sort(string $field, string $sort = null)   X-Ref
Generate SQL expression for sorting group concatenated fields

param: string $field The original field or SQL expression
param: string|null $sort A valid SQL ORDER BY to sort the concatenated fields, if omitted then $field will be used
return: string