Class database_driver

Description

Located in /sources/database.php (line 401)


	
			
Variable Summary
Method Summary
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])
void add_table_field (ID_TEXT $table_name, ID_TEXT $name, ID_TEXT $_type, [?mixed $default = NULL])
void alter_table_field (ID_TEXT $table_name, ID_TEXT $name, ID_TEXT $_type, [?ID_TEXT $new_name = NULL])
void change_primary_key (ID_TEXT $table_name, array $new_key)
void create_index (ID_TEXT $table_name, ID_TEXT $index_name, array $fields, [ID_TEXT $unique_key_field = 'id'])
void create_table (ID_TEXT $table_name, array $fields, [boolean $skip_size_check = false], [boolean $skip_null_check = false])
void delete_index_if_exists (ID_TEXT $table_name, ID_TEXT $index_name)
void delete_table_field (ID_TEXT $table_name, ID_TEXT $name)
void drop_if_exists (ID_TEXT $table)
string get_table_prefix ()
void promote_text_field_to_comcode (ID_TEXT $table_name, ID_TEXT $name, [ID_TEXT $key = 'id'], [integer $level = 2], [boolean $in_assembly = false])
?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 = ''])
void query_delete (string $table, [?array $where_map = NULL], [string $end = ''], [?integer $max = NULL], [?integer $start = NULL], [boolean $fail_ok = false])
integer query_insert (string $table, array $map, [boolean $ret = false], [boolean $fail_ok = false], [boolean $save_as_volatile = false])
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])
?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])
mixed query_value (string $table, string $select, [?array $where_map = NULL], [string $end = ''], [boolean $fail_ok = false])
?mixed query_value_null_ok (string $table, string $select, [?array $where_map = NULL], [string $end = ''], [boolean $fail_ok = false])
?mixed query_value_null_ok_full (string $query, [boolean $fail_ok = false])
void refresh_field_definition (ID_TEXT $type)
void rename_table (ID_TEXT $old, ID_TEXT $new)
boolean table_exists (ID_TEXT $tablename)
string _get_where_expand (string $table, [?array $select_map = NULL], [?array $where_map = NULL], [string $end = ''])
?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])
mixed _query_value (array $values)
Variables
mixed $connection_read (line 405)
mixed $connection_write (line 405)
mixed $static_ob (line 412)
mixed $table_exists_cache (line 410)
mixed $table_prefix (line 404)
mixed $text_lookup_cache (line 408)
mixed $text_lookup_original_cache (line 407)
Methods
Constructor database_driver (line 425)

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)
add_table_field (line 1183)

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)
alter_table_field (line 1197)

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_primary_key (line 1209)

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
create_index (line 1134)

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_table (line 1120)

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_index_if_exists (line 1146)

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_table_field (line 1237)

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_if_exists (line 1157)

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_table_prefix (line 458)

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_'.

  • return: The table prefix
string get_table_prefix ()
initialise_filesystem_db (line 810)

Initialise a filesystem DB that we can use for caching.

void initialise_filesystem_db ()
promote_text_field_to_comcode (line 1225)

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
query (line 926)

This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available (see below).

  • return: The results (NULL: no results)
?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)
query_delete (line 643)

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)
query_insert (line 473)

Insert a row.

  • return: The id of the new 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)
query_select (line 837)

Get the DB results found from the specified parameters.

  • return: The results
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)
query_update (line 699)

Update (edit) a row in the database.

  • return: The number of touched records (NULL: hasn't been asked / error)
?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)
query_value (line 580)

Get the specified value from the database. This is a first value of the first row returned.

  • return: The 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)
query_value_null_ok (line 612)

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.

  • return: The first value of the first row returned (NULL: nothing found, or null value found)
?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)
query_value_null_ok_full (line 626)

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.

  • return: The first value of the first row returned (NULL: nothing found, or null value found)
?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)
refresh_field_definition (line 1248)

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_table (line 1169)

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
table_exists (line 546)

Check if a table exists.

  • return: Whether it exists
boolean table_exists (ID_TEXT $tablename)
  • ID_TEXT $tablename: The table name
_get_where_expand (line 761)

Create a SELECT query from some abstract data.

  • return: SQL query
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
_query (line 951)

This function is a very basic query executor. It shouldn't usually be used by you, as there are specialised abstracted versions available.

  • return: The results (NULL: no results)
?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)
_query_value (line 594)

Extract the first of the first of the list of maps.

  • return: The first value of the first row in the list
mixed _query_value (array $values)
  • array $values: The list of maps

Documentation generated on Sun, 02 Jan 2011 23:12:46 +0000 by phpDocumentor 1.4.3