interface tools_interface

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

Methods

bool|string[]
perform_schema_changes(array $schema_changes)

Handle passed database update array.

array
sql_list_tables()

Gets a list of tables in the database.

bool
sql_table_exists(string $table_name)

Check if table exists

bool|string[]
sql_create_table(string $table_name, array $table_data)

Create SQL Table

bool|string[]
sql_table_drop(string $table_name)

Drop Table

array
sql_list_columns(string $table_name)

Gets a list of columns of a table.

bool
sql_column_exists(string $table_name, string $column_name)

Check whether a specified column exist in a table

bool|string[]
sql_column_add(string $table_name, string $column_name, array $column_data)

Add new column

bool|string[]
sql_column_change(string $table_name, string $column_name, array $column_data)

Change column type (not name!)

bool|string[]
sql_column_remove(string $table_name, string $column_name)

Drop column

array
sql_list_index(string $table_name)

List all of the indices that belong to a table

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.

bool|string[]
sql_create_index(string $table_name, string $index_name, string|array $column)

Add index

bool|string[]
sql_index_drop(string $table_name, string $index_name)

Drop Index

bool|string[]
sql_unique_index_exists(string $table_name, string $index_name)

Check if a specified index exists in table.

bool|string[]
sql_create_unique_index(string $table_name, string $index_name, string|array $column)

Add unique index

bool|string[]
sql_create_primary_key(string $table_name, string|array $column)

Add primary key

Details

at line 46
bool|string[] perform_schema_changes(array $schema_changes)

Handle passed database update array.

Expected structure... Key being one of the following drop_tables: Drop tables add_tables: Add tables change_columns: Column changes (only type, not name) add_columns: Add columns to a table drop_keys: Dropping keys drop_columns: Removing/Dropping columns add_primary_keys: adding primary keys add_unique_index: adding an unique index add_index: adding an index (can be column:index_size 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

bool|string[]

at line 53
array sql_list_tables()

Gets a list of tables in the database.

Return Value

array

Array of table names (all lower case)

at line 62
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 72
bool|string[] 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

bool|string[]

True if the statements have been executed

at line 81
bool|string[] sql_table_drop(string $table_name)

Drop Table

Parameters

string $table_name

The table name to drop

Return Value

bool|string[]

True if the statements have been executed

at line 90
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)

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

at line 111
bool|string[] sql_column_add(string $table_name, string $column_name, array $column_data)

Add new column

Parameters

string $table_name

Table to modify

string $column_name

Name of the column to add

array $column_data

Column data

Return Value

bool|string[]

True if the statements have been executed

at line 122
bool|string[] sql_column_change(string $table_name, string $column_name, array $column_data)

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

Return Value

bool|string[]

True if the statements have been executed

at line 132
bool|string[] sql_column_remove(string $table_name, string $column_name)

Drop column

Parameters

string $table_name

Table to modify

string $column_name

Name of the column to drop

Return Value

bool|string[]

True if the statements have been executed

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

at line 155
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 166
bool|string[] 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

bool|string[]

True if the statements have been executed

at line 176
bool|string[] 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

bool|string[]

True if the statements have been executed

at line 188
bool|string[] 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|string[]

True if index exists, else false

at line 199
bool|string[] 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

bool|string[]

True if the statements have been executed

at line 209
bool|string[] sql_create_primary_key(string $table_name, string|array $column)

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

Return Value

bool|string[]

True if the statements have been executed