phpBB API Documentation
Class

phpbb_db_tools

class phpbb_db_tools

Database Tools for handling cross-db actions such as altering columns, etc.

Currently not supported is returning SQL for creating tables.

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
array $supported_dbms A list of supported DBMS.
$return_statements This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).

Methods

phpbb_db_tools(phpbb_dbal $db, bool $return_statements = false)

Constructor.

array sql_list_tables()

Gets a list of tables in the database.

bool sql_table_exists(string $table_name)

Check if table exists

array sql_create_table(string $table_name, array $table_data)

Create SQL Table

perform_schema_changes($schema_changes)

Handle passed database update array.

array sql_list_columns(string $table)

Gets a list of columns of a table.

bool sql_column_exists(string $table, string $column_name)

Check whether a specified column exist in a table

bool sql_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

_sql_run_sql($statements)

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

sql_prepare_column_data($table_name, $column_name, $column_data)

Function to prepare some column information for better usage

sql_column_add($table_name, $column_name, $column_data, $inline = false)

Add new column

sql_column_remove($table_name, $column_name, $inline = false)

Drop column

sql_index_drop($table_name, $index_name)

Drop Index

sql_table_drop($table_name)

Drop Table

sql_create_primary_key($table_name, $column, $inline = false)

Add primary key

sql_create_unique_index($table_name, $index_name, $column)

Add unique index

sql_create_index($table_name, $index_name, $column)

Add index

sql_list_index($table_name)

List all of the indices that belong to a table, does not count: * UNIQUE indices * PRIMARY keys

sql_column_change($table_name, $column_name, $column_data, $inline = false)

Change column type (not name!)

Details

at line 308
public phpbb_db_tools(phpbb_dbal $db, bool $return_statements = false)

Constructor.

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

Parameters

phpbb_dbal $db DBAL object
bool $return_statements True if only statements should be returned and no SQL being executed

at line 355
public array sql_list_tables()

Gets a list of tables in the database.

Return Value

array Array of table names (all lower case)

at line 417
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

at line 439
public array 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 Statements if $return_statements is true.

at line 691
public perform_schema_changes($schema_changes)

Handle passed database update array.

Expected structure... Key being one of the following 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}), )

For more information have a look at /develop/createschemafiles.php (only available through SVN)

Parameters

$schema_changes

at line 1076
public array sql_list_columns(string $table)

Gets a list of columns of a table.

Parameters

string $table Table name

Return Value

array Array of column names (all lower case)

at line 1176
public bool sql_column_exists(string $table, string $column_name)

Check whether a specified column exist in a table

Parameters

string $table Table to check
string $column_name Column to check

Return Value

bool True if column exists, false otherwise

at line 1191
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

at line 1296
public bool sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

Does not return 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

at line 1417
public _sql_run_sql($statements)

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

Parameters

$statements

at line 1448
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

at line 1679
public sql_column_add($table_name, $column_name, $column_data, $inline = false)

Add new column

Parameters

$table_name
$column_name
$column_data
$inline

at line 1806
public sql_column_remove($table_name, $column_name, $inline = false)

Drop column

Parameters

$table_name
$column_name
$inline

at line 1948
public sql_index_drop($table_name, $index_name)

Drop Index

Parameters

$table_name
$index_name

at line 1978
public sql_table_drop($table_name)

Drop Table

Parameters

$table_name

at line 2046
public sql_create_primary_key($table_name, $column, $inline = false)

Add primary key

Parameters

$table_name
$column
$inline

at line 2135
public sql_create_unique_index($table_name, $index_name, $column)

Add unique index

Parameters

$table_name
$index_name
$column

at line 2172
public sql_create_index($table_name, $index_name, $column)

Add index

Parameters

$table_name
$index_name
$column

at line 2228
public sql_list_index($table_name)

List all of the indices that belong to a table, does not count: * UNIQUE indices * PRIMARY keys

Parameters

$table_name

at line 2320
public sql_column_change($table_name, $column_name, $column_data, $inline = false)

Change column type (not name!)

Parameters

$table_name
$column_name
$column_data
$inline