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
)
string
The database name
string
The database server
string
The connection username
string
The connection password
string
The table prefix
boolean
Whether to on error echo an error and return with a NULL, rather than giving a critical error
\?object
Static 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
string
The complete SQL query
\?integer
The maximum number of rows to affect (null: no limit)
\?integer
The start row to affect (null: no specification)
boolean
Whether to output an error on failure
boolean
Whether to get an insert ID
\?array
Extra 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)
string
All 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)
boolean
Whether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to git)
\?mixed
The 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_TEXT
The table name
\ID_TEXT
The field name
\ID_TEXT
The field type
\?mixed
The default value (null: no default)
alter_table_field(\ID_TEXT $table_name, \ID_TEXT $name, \ID_TEXT $_type, \?ID_TEXT $new_name = null
)
\ID_TEXT
The table name
\ID_TEXT
The field name
\ID_TEXT
The new field type
\?ID_TEXT
The new field name (null: leave name)
change_primary_key(\ID_TEXT $table_name, array $new_key)
\ID_TEXT
The name of the table to create the index on
array
A 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_TEXT
The table name
\ID_TEXT
The index name
array
The fields
\ID_TEXT
The 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_TEXT
The table name
array
The fields
boolean
Whether to skip the size check for the table (only do this for addon modules that don't need to support anything other than MySQL)
boolean
Whether to skip the check for NULL string fields
boolean
Whether 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_TEXT
The table name
\ID_TEXT
The index name
delete_table_field(\ID_TEXT $table_name, \ID_TEXT $name)
\ID_TEXT
The table name
\ID_TEXT
The field name
drop_table_if_exists(\ID_TEXT $table)
\ID_TEXT
The table name
get_table_prefix() : string
string
The 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_TEXT
The table name
\ID_TEXT
The field name
\ID_TEXT
The tables key field name
integer
The translation level to use
boolean
Whether 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
string
The complete SQL query
\?integer
The maximum number of rows to affect (null: no limit)
\?integer
The start row to affect (null: no specification)
boolean
Whether to output an error on failure
boolean
Whether to skip the query safety check
\?array
Extra 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)
string
All 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)
\?mixed
The 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
)
string
The table name
\?array
The WHERE map [will all be AND'd together] (null: no conditions)
string
Something to tack onto the end of the statement
\?integer
The maximum number of rows to delete (null: no limit)
\?integer
The starting row to delete (null: no specific start)
boolean
Whether 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
string
The table name
array
The insertion map
boolean
Whether to return the auto-insert-id
boolean
Whether to allow failure (outputting a message instead of exiting completely)
boolean
Whether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to git)
integer
The 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.
string
The complete SQL query
array
The query parameters (a map)
\?integer
The maximum number of rows to affect (null: no limit)
\?integer
The start row to affect (null: no specification)
boolean
Whether to output an error on failure
boolean
Whether to skip the query safety check
\?array
Extra 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)
string
All 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)
\?mixed
The 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.
string
The table name
\?array
The SELECT map (null: all fields)
\?array
The WHERE map [will all be AND'd together] (null: no conditions)
string
Something to tack onto the end of the SQL query
\?integer
The maximum number of rows to select (null: get all)
\?integer
The starting row to select (null: start at first)
boolean
Whether to allow failure (outputting a message instead of exiting completely)
\?array
Extra 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)
array
The 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
string
The table name
string
The field to select
\?array
The WHERE map [will all be AND'd together] (null: no where conditions)
string
Something to tack onto the end
boolean
Whether to allow failure (outputting a message instead of exiting completely)
\?array
Extra 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)
mixed
The 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
string
The table name
string
The field to select
\?array
The WHERE map [will all be AND'd together] (null: no where conditions)
string
Something to tack onto the end
boolean
Whether to allow failure (outputting a message instead of exiting completely)
\?array
Extra 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)
\?mixed
The 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
string
The table name
array
The UPDATE map
\?array
The WHERE map [will all be AND'd together] (null: no conditions)
string
Something to tack onto the end of the statement
\?integer
The maximum number of rows to update (null: no limit)
\?integer
The starting row to update (null: no specific start)
boolean
Whether to get the number of touched rows. WARNING: Do not use in core Composr code as it does not work on all database drivers
boolean
Whether to allow failure (outputting a message instead of exiting completely)
\?integer
The 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
string
The complete SQL query
boolean
Whether to allow failure (outputting a message instead of exiting completely)
boolean
Whether to skip the query safety check
\?array
Extra 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)
\?mixed
The first value of the first row returned (null: nothing found, or null value found)refresh_field_definition(\ID_TEXT $type)
\ID_TEXT
The field type
rename_table(\ID_TEXT $old, \ID_TEXT $new)
\ID_TEXT
The old table name
\ID_TEXT
The new table name
table_exists(\ID_TEXT $tablename) : boolean
\ID_TEXT
The table name
boolean
Whether it existstable_is_locked(\ID_TEXT $table) : boolean
\ID_TEXT
The table name
boolean
Whether 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_TEXT
Language field name
\ID_TEXT
SQL field name reference_automatic_lang_fields(string $table, string $full_table, array $select, \?array $where_map, string $end, \?array $lang_fields)
string
The table name
string
The table name, with prefix too
array
The SELECT map
\?array
The WHERE map [will all be AND'd together] (null: no conditions)
string
Something to tack onto the end of the SQL query
\?array
Extra 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
array
The list of maps
mixed
The 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