Database handling.
| package | core |
|---|
__construct(string $db_name, string $db_host, string $db_user, string $db_password, string $table_prefix, boolean $fail_ok= false, \?object $static= null)
stringThe database name
stringThe database server
stringThe connection username
stringThe connection password
stringThe table prefix
booleanWhether to on error echo an error and return with a NULL, rather than giving a critical error
\?objectStatic call object (null: use global static call object)
_query(string $query, \?integer $max= null, \?integer $start= null, boolean $fail_ok= false, boolean $get_insert_id= false, \?array $lang_fields= null, string $field_prefix= '', boolean $save_as_volatile= false) : \?mixed
stringThe complete SQL query
\?integerThe maximum number of rows to affect (null: no limit)
\?integerThe start row to affect (null: no specification)
booleanWhether to output an error on failure
booleanWhether to get an insert ID
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
stringAll the core fields have a prefix of this on them, so when we fiddle with language lookup we need to use this (only consider this if you're setting $lang_fields)
booleanWhether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to git)
\?mixedThe results (null: no result set) (empty array: empty result set)add_table_field(\ID_TEXT $table_name, \ID_TEXT $name, \ID_TEXT $_type, \?mixed $default = null)
\ID_TEXTThe table name
\ID_TEXTThe field name
\ID_TEXTThe field type
\?mixedThe default value (null: no default)
alter_table_field(\ID_TEXT $table_name, \ID_TEXT $name, \ID_TEXT $_type, \?ID_TEXT $new_name = null)
\ID_TEXTThe table name
\ID_TEXTThe field name
\ID_TEXTThe new field type
\?ID_TEXTThe new field name (null: leave name)
change_primary_key(\ID_TEXT $table_name, array $new_key)
\ID_TEXTThe name of the table to create the index on
arrayA list of fields to put in the new key
create_index(\ID_TEXT $table_name, \ID_TEXT $index_name, array $fields, \ID_TEXT $unique_key_field = 'id')
\ID_TEXTThe table name
\ID_TEXTThe index name
arrayThe fields
\ID_TEXTThe name of the unique key field for the table
create_table(\ID_TEXT $table_name, array $fields, boolean $skip_size_check= false, boolean $skip_null_check= false, boolean $save_bytes= false)
If a field type starts '*', then it is part of that field's key. If it starts '?', then it is an optional field.
\ID_TEXTThe table name
arrayThe fields
booleanWhether to skip the size check for the table (only do this for addon modules that don't need to support anything other than MySQL)
booleanWhether to skip the check for NULL string fields
booleanWhether to use lower-byte table storage, with tradeoffs of not being able to support all unicode characters; use this if key length is an issue
delete_index_if_exists(\ID_TEXT $table_name, \ID_TEXT $index_name)
\ID_TEXTThe table name
\ID_TEXTThe index name
delete_table_field(\ID_TEXT $table_name, \ID_TEXT $name)
\ID_TEXTThe table name
\ID_TEXTThe field name
drop_table_if_exists(\ID_TEXT $table)
\ID_TEXTThe table name
get_table_prefix() : string
stringThe table prefixinitialise_filesystem_db()
promote_text_field_to_comcode(\ID_TEXT $table_name, \ID_TEXT $name, \ID_TEXT $key= 'id', integer $level= 2, boolean $in_assembly= false)
| set | 1 2 3 4 |
|---|
\ID_TEXTThe table name
\ID_TEXTThe field name
\ID_TEXTThe tables key field name
integerThe translation level to use
booleanWhether our data is already stored in Tempcode assembly format
query(string $query, \?integer $max= null, \?integer $start= null, boolean $fail_ok= false, boolean $skip_safety_check= false, \?array $lang_fields= null, string $field_prefix= '') : \?mixed
stringThe complete SQL query
\?integerThe maximum number of rows to affect (null: no limit)
\?integerThe start row to affect (null: no specification)
booleanWhether to output an error on failure
booleanWhether to skip the query safety check
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
stringAll the core fields have a prefix of this on them, so when we fiddle with language lookup we need to use this (only consider this if you're setting $lang_fields)
\?mixedThe results (null: no result set) (empty array: empty result set)query_delete(string $table, \?array $where_map= null, string $end= '', \?integer $max= null, \?integer $start= null, boolean $fail_ok= false)
stringThe table name
\?arrayThe WHERE map [will all be AND'd together] (null: no conditions)
stringSomething to tack onto the end of the statement
\?integerThe maximum number of rows to delete (null: no limit)
\?integerThe starting row to delete (null: no specific start)
booleanWhether to allow failure (outputting a message instead of exiting completely)
query_insert(string $table, array $map, boolean $ret= false, boolean $fail_ok= false, boolean $save_as_volatile= false) : integer
stringThe table name
arrayThe insertion map
booleanWhether to return the auto-insert-id
booleanWhether to allow failure (outputting a message instead of exiting completely)
booleanWhether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to git)
integerThe ID of the new rowquery_parameterised(string $query, array $parameters, \?integer $max= null, \?integer $start= null, boolean $fail_ok= false, boolean $skip_safety_check= false, \?array $lang_fields= null, string $field_prefix= '') : \?mixed
Assumes nothing looking like {example} is in the query already. Also supports {prefix} for encoding the table prefix. Lots of programmers like to do queries like this as it reduces the chance of accidentally forgetting to escape a parameter inserted directly/manually within a longer query. Usually in Composr we use APIs like query_select, which avoids the need for SQL all-together, but this doesn't work for all patterns of query.
stringThe complete SQL query
arrayThe query parameters (a map)
\?integerThe maximum number of rows to affect (null: no limit)
\?integerThe start row to affect (null: no specification)
booleanWhether to output an error on failure
booleanWhether to skip the query safety check
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
stringAll the core fields have a prefix of this on them, so when we fiddle with language lookup we need to use this (only consider this if you're setting $lang_fields)
\?mixedThe results (null: no result set) (empty array: empty result set)query_select(string $table, \?array $select= null, \?array $where_map= null, string $end= '', \?integer $max= null, \?integer $start= null, boolean $fail_ok= false, \?array $lang_fields= null) : array
Only use this if you're where condition is a series of AND clauses doing simple property comparisons.
stringThe table name
\?arrayThe SELECT map (null: all fields)
\?arrayThe WHERE map [will all be AND'd together] (null: no conditions)
stringSomething to tack onto the end of the SQL query
\?integerThe maximum number of rows to select (null: get all)
\?integerThe starting row to select (null: start at first)
booleanWhether to allow failure (outputting a message instead of exiting completely)
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
arrayThe results (empty array: empty result set)query_select_value(string $table, string $selected_value, \?array $where_map= null, string $end= '', boolean $fail_ok= false, \?array $lang_fields= null) : mixed
stringThe table name
stringThe field to select
\?arrayThe WHERE map [will all be AND'd together] (null: no where conditions)
stringSomething to tack onto the end
booleanWhether to allow failure (outputting a message instead of exiting completely)
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
mixedThe first value of the first row returnedquery_select_value_if_there(string $table, string $select, \?array $where_map= null, string $end= '', boolean $fail_ok= false, \?array $lang_fields= null) : \?mixed
stringThe table name
stringThe field to select
\?arrayThe WHERE map [will all be AND'd together] (null: no where conditions)
stringSomething to tack onto the end
booleanWhether to allow failure (outputting a message instead of exiting completely)
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
\?mixedThe first value of the first row returned (null: nothing found, or null value found)query_update(string $table, array $update_map, \?array $where_map= null, string $end= '', \?integer $max= null, \?integer $start= null, boolean $num_touched= false, boolean $fail_ok= false) : \?integer
stringThe table name
arrayThe UPDATE map
\?arrayThe WHERE map [will all be AND'd together] (null: no conditions)
stringSomething to tack onto the end of the statement
\?integerThe maximum number of rows to update (null: no limit)
\?integerThe starting row to update (null: no specific start)
booleanWhether to get the number of touched rows. WARNING: Do not use in core Composr code as it does not work on all database drivers
booleanWhether to allow failure (outputting a message instead of exiting completely)
\?integerThe number of touched records (null: hasn't been asked / error)query_value_if_there(string $query, boolean $fail_ok= false, boolean $skip_safety_check= false, \?array $lang_fields= null) : \?mixed
stringThe complete SQL query
booleanWhether to allow failure (outputting a message instead of exiting completely)
booleanWhether to skip the query safety check
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
\?mixedThe first value of the first row returned (null: nothing found, or null value found)refresh_field_definition(\ID_TEXT $type)
\ID_TEXTThe field type
rename_table(\ID_TEXT $old, \ID_TEXT $new)
\ID_TEXTThe old table name
\ID_TEXTThe new table name
table_exists(\ID_TEXT $tablename) : boolean
\ID_TEXTThe table name
booleanWhether it existstable_is_locked(\ID_TEXT $table) : boolean
\ID_TEXTThe table name
booleanWhether the table is lockedtranslate_field_ref(\ID_TEXT $field_name) : \ID_TEXT
Assumes the query has separately been informed of the $lang_fields parameter (which is automatic for query_select).
\ID_TEXTLanguage field name
\ID_TEXTSQL field name reference_automatic_lang_fields(string $table, string $full_table, array $select, \?array $where_map, string $end, \?array $lang_fields)
stringThe table name
stringThe table name, with prefix too
arrayThe SELECT map
\?arrayThe WHERE map [will all be AND'd together] (null: no conditions)
stringSomething to tack onto the end of the SQL query
\?arrayExtra language fields to join in for cache-prefilling. You only need to send this if you are doing a JOIN and carefully craft your query so table field names won't conflict (null: none)
_query_select_value(array $values) : mixed
arrayThe list of maps
mixedThe first value of the first row in the list$connection_read
$connection_write
$dedupe_mode
false$static_ob
$table_exists_cache
$table_prefix
$text_lookup_cache
$text_lookup_original_cache