Construct a database driver from connection parameters.
database_driver
database_driver
(string $db_name, string $db_host, string $db_user, string $db_password, string $table_prefix, [boolean $fail_ok = false], [?object $static = NULL])
-
string
$db_name: The database name
-
string
$db_host: The database server
-
string
$db_user: The connection username
-
string
$db_password: The connection password
-
string
$table_prefix: The table prefix
-
boolean
$fail_ok: Whether to on error echo an error and return with a NULL, rather than giving a critical error
-
?object
$static: Static call object (NULL: use global static call object)
Adds a field to an existing table.
void
add_table_field
(ID_TEXT $table_name, ID_TEXT $name, ID_TEXT $_type, [?mixed $default = NULL])
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$name: The field name
-
ID_TEXT
$_type: The field type
-
?mixed
$default: The default value (NULL: no default)
Change the type of a DB field in a table. Note: this function does not support ascession/decession of translatability
void
alter_table_field
(ID_TEXT $table_name, ID_TEXT $name, ID_TEXT $_type, [?ID_TEXT $new_name = NULL])
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$name: The field name
-
ID_TEXT
$_type: The new field type
-
?ID_TEXT
$new_name: The new field name (NULL: leave name)
Change the primary key of a table.
void
change_primary_key
(ID_TEXT $table_name, array $new_key)
-
ID_TEXT
$table_name: The name of the table to create the index on
-
array
$new_key: A list of fields to put in the new key
Add an index to a table without disturbing the contents, after the table has been created.
void
create_index
(ID_TEXT $table_name, ID_TEXT $index_name, array $fields, [ID_TEXT $unique_key_field = 'id'])
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$index_name: The index name
-
array
$fields: The fields
-
ID_TEXT
$unique_key_field: The name of the unique key field for the table
Create a table with the given name and the given array of field name to type mappings.
If a field type starts '*', then it is part of that field's key. If it starts '?', then it is an optional field.
void
create_table
(ID_TEXT $table_name, array $fields, [boolean $skip_size_check = false], [boolean $skip_null_check = false])
-
ID_TEXT
$table_name: The table name
-
array
$fields: The fields
-
boolean
$skip_size_check: 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
$skip_null_check: Whether to skip the check for NULL string fields
Delete an index from a table.
void
delete_index_if_exists
(ID_TEXT $table_name, ID_TEXT $index_name)
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$index_name: The index name
Delete the specified field from the specified table.
void
delete_table_field
(ID_TEXT $table_name, ID_TEXT $name)
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$name: The field name
Drop the given table, or if it doesn't exist, silently return.
void
drop_if_exists
(ID_TEXT $table)
-
ID_TEXT
$table: The table name
Get the table prefixes used for all ocPortal tables, commonly used when you are installing ocPortal in the same database as your forums. The default table prefix is 'ocp4_'.
string
get_table_prefix
()
Initialise a filesystem DB that we can use for caching.
void
initialise_filesystem_db
()
If a text field has picked up Comcode support, we will need to run this.
void
promote_text_field_to_comcode
(ID_TEXT $table_name, ID_TEXT $name, [ID_TEXT $key = 'id'], [integer $level = 2], [boolean $in_assembly = false])
-
ID_TEXT
$table_name: The table name
-
ID_TEXT
$name: The field name
-
ID_TEXT
$key: The tables key field name
-
integer
$level: The translation level to use
-
boolean
$in_assembly: Whether our data is already stored in Tempcode assembly format
This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available (see below).
?mixed
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 = ''])
-
string
$query: The complete SQL query
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to output an error on failure
-
boolean
$skip_safety_check: Whether to skip the query safety check
-
?array
$lang_fields: 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
$field_prefix: 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)
Deletes rows from the specified table, that match the specified conditions (if any). It may be limited to a row range (it is likely, only a maximum, of 1, will be used, if any kind of range at all).
void
query_delete
(string $table, [?array $where_map = NULL], [string $end = ''], [?integer $max = NULL], [?integer $start = NULL], [boolean $fail_ok = false])
-
string
$table: The table name
-
?array
$where_map: The WHERE map [will all be AND'd together] (NULL: no conditions)
-
string
$end: Something to tack onto the end of the statement
-
?integer
$max: The maximum number of rows to delete (NULL: no limit)
-
?integer
$start: The starting row to delete (NULL: no specific start)
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
Insert a row.
integer
query_insert
(string $table, array $map, [boolean $ret = false], [boolean $fail_ok = false], [boolean $save_as_volatile = false])
-
string
$table: The table name
-
array
$map: The insertion map
-
boolean
$ret: Whether to return the auto-insert-id
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
-
boolean
$save_as_volatile: Whether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to subversion)
Get the DB results found from the specified parameters.
array
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])
-
string
$table: The table name
-
?array
$select: The SELECT map (NULL: all fields)
-
?array
$where_map: The WHERE map [will all be AND'd together] (NULL: no conditions)
-
string
$end: Something to tack onto the end of the SQL query
-
?integer
$max: The maximum number of rows to select (NULL: get all)
-
?integer
$start: The starting row to select (NULL: start at first)
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
-
?array
$lang_fields: 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)
Update (edit) a row in the database.
?integer
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])
-
string
$table: The table name
-
array
$update_map: The UPDATE map
-
?array
$where_map: The WHERE map [will all be AND'd together] (NULL: no conditions)
-
string
$end: Something to tack onto the end of the statement
-
?integer
$max: The maximum number of rows to update (NULL: no limit)
-
?integer
$start: The starting row to update (NULL: no specific start)
-
boolean
$num_touched: Whether to get the number of touched rows. WARNING: Do not use in core ocPortal code as it does not work on all database drivers
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
Get the specified value from the database. This is a first value of the first row returned.
mixed
query_value
(string $table, string $select, [?array $where_map = NULL], [string $end = ''], [boolean $fail_ok = false])
-
string
$table: The table name
-
string
$select: The field to select
-
?array
$where_map: The WHERE map [will all be AND'd together] (NULL: no where conditions)
-
string
$end: Something to tack onto the end
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
Get the specified value from the database, or NULL if it is not there (or if the value itself is NULL). This is good for detection existence of records, or for use if they might may or may not be present.
?mixed
query_value_null_ok
(string $table, string $select, [?array $where_map = NULL], [string $end = ''], [boolean $fail_ok = false])
-
string
$table: The table name
-
string
$select: The field to select
-
?array
$where_map: The WHERE map [will all be AND'd together] (NULL: no where conditions)
-
string
$end: Something to tack onto the end
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
This function is a variant of query_value_null_ok, by the fact that it only accepts a complete (and perfect) SQL query, instead of assembling one itself from the specified parameters.
?mixed
query_value_null_ok_full
(string $query, [boolean $fail_ok = false])
-
string
$query: The complete SQL query
-
boolean
$fail_ok: Whether to allow failure (outputting a message instead of exiting completely)
If we've changed what $type is stored as, this function will need to be called to change the typing in the DB.
void
refresh_field_definition
(ID_TEXT $type)
-
ID_TEXT
$type: The field type
Rename the given table.
void
rename_table
(ID_TEXT $old, ID_TEXT $new)
-
ID_TEXT
$old: The old table name
-
ID_TEXT
$new: The new table name
Check if a table exists.
boolean
table_exists
(ID_TEXT $tablename)
-
ID_TEXT
$tablename: The table name
Create a SELECT query from some abstract data.
string
_get_where_expand
(string $table, [?array $select_map = NULL], [?array $where_map = NULL], [string $end = ''])
-
string
$table: The table to select from
-
?array
$select_map: List of field selections (NULL: all fields)
-
?array
$where_map: Map of conditions to enforce (NULL: no conditions)
-
string
$end: Additional stuff to tack onto the query
This function is a very basic query executor. It shouldn't usually be used by you, as there are specialised abstracted versions available.
?mixed
_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])
-
string
$query: The complete SQL query
-
?integer
$max: The maximum number of rows to affect (NULL: no limit)
-
?integer
$start: The start row to affect (NULL: no specification)
-
boolean
$fail_ok: Whether to output an error on failure
-
boolean
$get_insert_id: Whether to get an insert ID
-
?array
$lang_fields: 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
$field_prefix: 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
$save_as_volatile: Whether we are saving as a 'volatile' file extension (used in the XML DB driver, to mark things as being non-syndicated to subversion)
Extract the first of the first of the list of maps.
mixed
_query_value
(array $values)
-
array
$values: The list of maps