phpBB API Documentation
Class

phpbb\db\tools

class tools extends tools

Properties

$sql_layer Current sql layer
object $db
array $dbms_type_map The Column types for every database we support
array $unsigned_types A list of types being unsigned for better reference in some db's
$return_statements This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).

Methods

static array get_dbms_type_map()

Get the column types for every database we support

from tools
__construct(driver_interface $db, bool $return_statements = false)

Constructor.

from tools
null set_return_statements(bool $return_statements)

Setter for {@link $returnstatements returnstatements}.

from tools
array sql_list_tables()

Gets a list of tables in the database.

from tools
bool sql_table_exists(string $table_name)

Check if table exists

from tools
array|true sql_create_table(string $table_name, array $table_data)

Create SQL Table

from tools
null perform_schema_changes(array $schema_changes)

Handle passed database update array.

from tools
array sql_list_columns(string $table_name)

Gets a list of columns of a table.

from tools
bool sql_column_exists(string $table_name, string $column_name)

Check whether a specified column exist in a table

from tools
bool sql_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

from tools
bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

from tools
_sql_run_sql($statements)

Private method for performing sql statements (either execute them or return them)

from tools
sql_prepare_column_data($table_name, $column_name, $column_data)

Function to prepare some column information for better usage

from tools
array get_column_type(string $column_map_type)

Get the column's database type from the type map

from tools
array|true sql_column_add(string $table_name, string $column_name, array $column_data, bool $inline = false)

Add new column

from tools
array|true sql_column_remove(string $table_name, string $column_name, bool $inline = false)

Drop column

from tools
array|true sql_index_drop(string $table_name, string $index_name)

Drop Index

from tools
array|true sql_table_drop(string $table_name)

Drop Table

from tools
array|true sql_create_primary_key(string $table_name, string|array $column, bool $inline = false)

Add primary key

from tools
array|true sql_create_unique_index(string $table_name, string $index_name, string|array $column)

Add unique index

from tools
array|true sql_create_index(string $table_name, string $index_name, string|array $column)

Add index

from tools
array sql_list_index(string $table_name)

List all of the indices that belong to a table

from tools
array|true sql_column_change(string $table_name, string $column_name, array $column_data, bool $inline = false)

Change column type (not name!)

from tools
array get_existing_indexes(string $table_name, string $column_name, bool $unique = false)

Get a list with existing indexes for the column

from tools

Details

in tools at line 43
static public array get_dbms_type_map()

Get the column types for every database we support

Return Value

array

in tools at line 190
public __construct(driver_interface $db, bool $return_statements = false)

Constructor.

Set DB Object and set {@link $returnstatements returnstatements}.

Parameters

driver_interface $db Database connection
bool $return_statements True if only statements should be returned and no SQL being executed

in tools at line 231
public null set_return_statements(bool $return_statements)

Setter for {@link $returnstatements returnstatements}.

Parameters

bool $return_statements True if SQL should not be executed but returned as strings

Return Value

null

in tools at line 239
public array sql_list_tables()

Gets a list of tables in the database.

Return Value

array Array of table names (all lower case)

in tools at line 278
public bool sql_table_exists(string $table_name)

Check if table exists

Parameters

string $table_name The table name to check for

Return Value

bool true if table exists, else false

in tools at line 296
public array|true sql_create_table(string $table_name, array $table_data)

Create SQL Table

Parameters

string $table_name The table name to create
array $table_data Array containing table data.

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 450
public null perform_schema_changes(array $schema_changes)

Handle passed database update array.

Expected structure... Key being one of the following droptables: Drop tables addtables: Add tables changecolumns: Column changes (only type, not name) addcolumns: Add columns to a table dropkeys: Dropping keys dropcolumns: Removing/Dropping columns addprimarykeys: adding primary keys adduniqueindex: adding an unique index addindex: adding an index (can be column:indexsize if you need to provide size)

The values are in this format: {TABLE NAME} => array( {COLUMN NAME} => array({COLUMN TYPE}, {DEFAULT VALUE}, {OPTIONAL VARIABLES}), {KEY/INDEX NAME} => array({COLUMN NAMES}), )

Parameters

array $schema_changes

Return Value

null

in tools at line 831
public array sql_list_columns(string $table_name)

Gets a list of columns of a table.

Parameters

string $table_name Table name

Return Value

array Array of column names (all lower case)

in tools at line 900
public bool sql_column_exists(string $table_name, string $column_name)

Check whether a specified column exist in a table

Parameters

string $table_name Table to check
string $column_name Column to check

Return Value

bool True if column exists, false otherwise

in tools at line 910
public bool sql_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

Does not return PRIMARY KEY and UNIQUE indexes.

Parameters

string $table_name Table to check the index at
string $index_name The index name to check

Return Value

bool True if index exists, else false

in tools at line 970
public bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

NOTE: Does not return normal and PRIMARY KEY indexes

Parameters

string $table_name Table to check the index at
string $index_name The index name to check

Return Value

bool True if index exists, else false

in tools at line 1044
public _sql_run_sql($statements)

Private method for performing sql statements (either execute them or return them)

Parameters

$statements

in tools at line 1075
public sql_prepare_column_data($table_name, $column_name, $column_data)

Function to prepare some column information for better usage

Parameters

$table_name
$column_name
$column_data

in tools at line 1188
public array get_column_type(string $column_map_type)

Get the column's database type from the type map

Parameters

string $column_map_type

Return Value

array column type for this database and map type without length

in tools at line 1244
public array|true sql_column_add(string $table_name, string $column_name, array $column_data, bool $inline = false)

Add new column

Parameters

string $table_name Table to modify
string $column_name Name of the column to add
array $column_data Column data
bool $inline Whether the query should actually be run, or return a string for adding the column

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1278
public array|true sql_column_remove(string $table_name, string $column_name, bool $inline = false)

Drop column

Parameters

string $table_name Table to modify
string $column_name Name of the column to drop
bool $inline Whether the query should actually be run, or return a string for deleting the column

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1357
public array|true sql_index_drop(string $table_name, string $index_name)

Drop Index

Parameters

string $table_name Table to modify
string $index_name Name of the index to delete

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1382
public array|true sql_table_drop(string $table_name)

Drop Table

Parameters

string $table_name The table name to drop

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1419
public array|true sql_create_primary_key(string $table_name, string|array $column, bool $inline = false)

Add primary key

Parameters

string $table_name Table to modify
string|array $column Either a string with a column name, or an array with columns
bool $inline Whether the query should actually be run, or return a string for creating the key

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1491
public array|true sql_create_unique_index(string $table_name, string $index_name, string|array $column)

Add unique index

Parameters

string $table_name Table to modify
string $index_name Name of the unique index to create
string|array $column Either a string with a column name, or an array with columns

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1516
public array|true sql_create_index(string $table_name, string $index_name, string|array $column)

Add index

Parameters

string $table_name Table to modify
string $index_name Name of the index to create
string|array $column Either a string with a column name, or an array with columns

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1595
public array sql_list_index(string $table_name)

List all of the indices that belong to a table

NOTE: does not list - UNIQUE indices - PRIMARY keys

Parameters

string $table_name Table to check

Return Value

array Array with index names

in tools at line 1661
public array|true sql_column_change(string $table_name, string $column_name, array $column_data, bool $inline = false)

Change column type (not name!)

Parameters

string $table_name Table to modify
string $column_name Name of the column to modify
array $column_data Column data
bool $inline Whether the query should actually be run, or return a string for modifying the column

Return Value

array|true Statements to run, or true if the statements have been executed

in tools at line 1814
public array get_existing_indexes(string $table_name, string $column_name, bool $unique = false)

Get a list with existing indexes for the column

Parameters

string $table_name
string $column_name
bool $unique Should we get unique indexes or normal ones

Return Value

array Array with Index name => columns