class Table

Handles everything related to tables

Constants

PROP_SORTED_COLUMN

UI preferences properties

PROP_COLUMN_ORDER

PROP_COLUMN_VISIB

Properties

string $engine
string $type
array $uiprefs
array $errors
array $messages
protected string $_name
protected string $_db_name
protected DatabaseInterface $_dbi

Methods

__construct(string $table_name, string $db_name, DatabaseInterface|null $dbi = null)

No description

string
__toString()

returns table name

static Table
get(string $table_name, string $db_name, DatabaseInterface|null $dbi = null)

Table getter

string
getLastError()

return the last error

string
getLastMessage()

return the last message

string
getName(bool $backquoted = false)

returns table name

string
getDbName(bool $backquoted = false)

returns database name for this table

string
getFullName(bool $backquoted = false)

returns full name for table, including database name

bool
isEngine(array|string $engine)

Checks the storage engine used to create table

bool
isView()

returns whether the table is actually a view

bool
isUpdatableView()

Returns whether the table is actually an updatable view

bool
isMerge()

Checks if this is a merge table

mixed
getStatusInfo(string $info = null, bool $force_read = false, bool $disable_error = false)

Returns full table status info, or specific if $info provided this info is collected from information_schema

string
getStorageEngine()

Returns the Table storage Engine for current table.

string
getComment()

Returns the comments for current table.

string
getCollation()

Returns the collation for current table.

int
getNumRows()

Returns the info about no of rows for current table.

string
getRowFormat()

Returns the Row format for current table.

int
getAutoIncrement()

Returns the auto increment option for current table.

array
getCreateOptions()

Returns the array for CREATE statement for current table.

static string
generateFieldSpec(string $name, string $type, string $length = '', string $attribute = '', string $collation = '', bool|string $null = false, string $default_type = 'USER_DEFINED', string $default_value = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $move_to = '', array $columns_with_index = null, string $oldColumnName = null)

generates column specification for ALTER or CREATE TABLE syntax

bool
checkIfMinRecordsExist(int $min_records = 0)

Checks if the number of records in a table is at least equal to $min_records

mixed
countRecords(bool $force_exact = false)

Counts and returns (or displays) the number of records in a table

static string
generateAlter(string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, bool|string $null, string $default_type, string $default_value, string $extra, string $comment, string $virtuality, string $expression, string $move_to, array $columns_with_index = null)

Generates column specification for ALTER syntax

static int|bool
duplicateInfo(string $work, string $pma_table, array $get_fields, array $where_fields, array $new_fields)

Inserts existing entries in a PMA_* table by reading a value from an old entry

static bool
moveCopy(string $source_db, string $source_table, string|null $target_db, string $target_table, string $what, bool $move, string $mode)

Copies or renames table

static bool
isValidName(string $table_name, bool $is_backquoted = false)

checks if given name is a valid table name, currently if not empty, trailing spaces, '.', '/' and '\'

bool
rename(string $new_name, string $new_db = null)

renames table

array
getUniqueColumns(bool $backquoted = true, bool $fullName = true)

Get all unique columns

array
getIndexedColumns(bool $backquoted = true, bool $fullName = true)

Get all indexed columns

array
getColumns(bool $backquoted = true, bool $fullName = true)

Get all columns

mixed
getColumnsMeta()

Get meta info for fields in table

array
getNonGeneratedColumns(bool $backquoted = true)

Get non-generated columns in table

array
getUiPrefsFromDb()

Return UI preferences for this table from phpMyAdmin database.

true|Message
saveUiPrefsToDb()

Save this table's UI preferences into phpMyAdmin database.

void
loadUiPrefs()

Loads the UI preferences for this table.

mixed
getUiProp(string $property)

Get a property from UI preferences.

bool|Message
setUiProp(string $property, mixed $value, string $table_create_time = null)

Set a property from UI preferences.

true|Message
removeUiProp(string $property)

Remove a property from UI preferences.

array
getReservedColumnNames()

Get all column names which are MySQL reserved words

array
getNameAndTypeOfTheColumns()

Function to get the name and type of the columns of a table

getIndex(string $index)

Get index with index name

string
getSqlQueryForIndexCreateOrEdit(Index $index, bool $error)

Function to get the sql query for index creation or edit

bool
updateDisplayField(string $display_field, array $cfgRelation)

Function to handle update for display field

bool
updateInternalRelations(array $multi_edit_columns_name, array $destination_db, array $destination_table, array $destination_column, array $cfgRelation, array|null $existrel)

Function to get update query for updating internal relations

array
updateForeignKeys(array $destination_foreign_db, array $multi_edit_columns_name, array $destination_foreign_table, array $destination_foreign_column, array $options_array, string $table, array $existrel_foreign)

Function to handle foreign key updates

array|bool
getColumnGenerationExpression(string $column = null)

Returns the generation expression for virtual columns

mixed
showCreate()

Returns the CREATE statement for this table

int
getRealRowCountTable()

Returns the real row count for a table

array
getColumnsWithIndex(int $types)

Get columns with indexes

Details

at line 96
__construct(string $table_name, string $db_name, DatabaseInterface|null $dbi = null)

Parameters

string $table_name table name
string $db_name database name
DatabaseInterface|null $dbi database interface for the table

at line 114
string __toString()

returns table name

Return Value

string table name

See also

at line 128
static Table get(string $table_name, string $db_name, DatabaseInterface|null $dbi = null)

Table getter

Parameters

string $table_name table name
string $db_name database name
DatabaseInterface|null $dbi database interface for the table

Return Value

Table

at line 138
string getLastError()

return the last error

Return Value

string the last error

at line 148
string getLastMessage()

return the last message

Return Value

string the last message

at line 160
string getName(bool $backquoted = false)

returns table name

Parameters

bool $backquoted whether to quote name with backticks ``

Return Value

string table name

at line 175
string getDbName(bool $backquoted = false)

returns database name for this table

Parameters

bool $backquoted whether to quote name with backticks ``

Return Value

string database name for this table

at line 190
string getFullName(bool $backquoted = false)

returns full name for table, including database name

Parameters

bool $backquoted whether to quote name with backticks ``

Return Value

string

at line 205
bool isEngine(array|string $engine)

Checks the storage engine used to create table

Parameters

array|string $engine Checks the table engine against an array of engine strings or a single string, should be uppercase

Return Value

bool True, if $engine matches the storage engine for the table, False otherwise.

at line 226
bool isView()

returns whether the table is actually a view

Return Value

bool whether the given is a view

at line 262
bool isUpdatableView()

Returns whether the table is actually an updatable view

Return Value

bool whether the given is an updatable view

at line 286
bool isMerge()

Checks if this is a merge table

If the ENGINE of the table is MERGE or MRG_MYISAM (alias), this is a merge table.

Return Value

bool true if it is a merge table

at line 304
mixed getStatusInfo(string $info = null, bool $force_read = false, bool $disable_error = false)

Returns full table status info, or specific if $info provided this info is collected from information_schema

Parameters

string $info specific information to be fetched
bool $force_read read new rather than serving from cache
bool $disable_error if true, disables error message

Return Value

mixed

at line 360
string getStorageEngine()

Returns the Table storage Engine for current table.

Return Value

string Return storage engine info if it is set for the selected table else return blank.

at line 374
string getComment()

Returns the comments for current table.

Return Value

string Return comment info if it is set for the selected table or return blank.

at line 388
string getCollation()

Returns the collation for current table.

Return Value

string Return blank if collation is empty else return the collation info from table info.

at line 402
int getNumRows()

Returns the info about no of rows for current table.

Return Value

int Return no of rows info if it is not null for the selected table or return 0.

at line 417
string getRowFormat()

Returns the Row format for current table.

Return Value

string Return table row format info if it is set for the selected table or return blank.

at line 431
int getAutoIncrement()

Returns the auto increment option for current table.

Return Value

int Return auto increment info if it is set for the selected table or return blank.

at line 442
array getCreateOptions()

Returns the array for CREATE statement for current table.

Return Value

array Return options array info if it is set for the selected table or return blank.

at line 491
static string generateFieldSpec(string $name, string $type, string $length = '', string $attribute = '', string $collation = '', bool|string $null = false, string $default_type = 'USER_DEFINED', string $default_value = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $move_to = '', array $columns_with_index = null, string $oldColumnName = null)

generates column specification for ALTER or CREATE TABLE syntax

Parameters

string $name name
string $type type ('INT', 'VARCHAR', 'BIT', ...)
string $length length ('2', '5,2', '', ...)
string $attribute attribute
string $collation collation
bool|string $null with 'NULL' or 'NOT NULL'
string $default_type whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED
string $default_value default value for USER_DEFINED default type
string $extra 'AUTO_INCREMENT'
string $comment field comment
string $virtuality virtuality of the column
string $expression expression for the virtual column
string $move_to new position for column
array $columns_with_index Fields having PRIMARY or UNIQUE KEY indexes
string $oldColumnName Old column name

Return Value

string field specification

at line 666
bool checkIfMinRecordsExist(int $min_records = 0)

Checks if the number of records in a table is at least equal to $min_records

Parameters

int $min_records Number of records to check for in a table

Return Value

bool True, if at least $min_records exist, False otherwise.

at line 709
mixed countRecords(bool $force_exact = false)

Counts and returns (or displays) the number of records in a table

Parameters

bool $force_exact whether to force an exact count

Return Value

mixed the number of records if "retain" param is true, otherwise true

at line 824
static string generateAlter(string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, bool|string $null, string $default_type, string $default_value, string $extra, string $comment, string $virtuality, string $expression, string $move_to, array $columns_with_index = null)

Generates column specification for ALTER syntax

Parameters

string $oldcol old column name
string $newcol new column name
string $type type ('INT', 'VARCHAR', 'BIT', ...)
string $length length ('2', '5,2', '', ...)
string $attribute attribute
string $collation collation
bool|string $null with 'NULL' or 'NOT NULL'
string $default_type whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED
string $default_value default value for USER_DEFINED default type
string $extra 'AUTO_INCREMENT'
string $comment field comment
string $virtuality virtuality of the column
string $expression expression for the virtual column
string $move_to new position for column
array $columns_with_index Fields having PRIMARY or UNIQUE KEY indexes

Return Value

string field specification

See also

at line 879
static int|bool duplicateInfo(string $work, string $pma_table, array $get_fields, array $where_fields, array $new_fields)

Inserts existing entries in a PMA_* table by reading a value from an old entry

Parameters

string $work The array index, which Relation feature to check ('relwork', 'commwork', ...)
string $pma_table The array index, which PMA-table to update ('bookmark', 'relation', ...)
array $get_fields Which fields will be SELECT'ed from the old entry
array $where_fields Which fields will be used for the WHERE query (array('FIELDNAME' => 'FIELDVALUE'))
array $new_fields Which fields will be used as new VALUES. These are the important keys which differ from the old entry (array('FIELDNAME' => 'NEW FIELDVALUE'))

Return Value

int|bool

at line 967
static bool moveCopy(string $source_db, string $source_table, string|null $target_db, string $target_table, string $what, bool $move, string $mode)

Copies or renames table

Parameters

string $source_db source database
string $source_table source table
string|null $target_db target database
string $target_table target table
string $what what to be moved or copied (data, dataonly)
bool $move whether to move
string $mode mode

Return Value

bool true if success, false otherwise

at line 1519
static bool isValidName(string $table_name, bool $is_backquoted = false)

checks if given name is a valid table name, currently if not empty, trailing spaces, '.', '/' and '\'

Parameters

string $table_name name to check
bool $is_backquoted whether this name is used inside backquotes or not

Return Value

bool whether the string is valid or not

See also

at line 1557
bool rename(string $new_name, string $new_db = null)

renames table

Parameters

string $new_name new table name
string $new_db new database name

Return Value

bool success

at line 1665
array getUniqueColumns(bool $backquoted = true, bool $fullName = true)

Get all unique columns

returns an array with all columns with unique content, in fact these are all columns being single indexed in PRIMARY or UNIQUE

e.g. - PRIMARY(id) // id - UNIQUE(name) // name - PRIMARY(fk_id1, fk_id2) // NONE - UNIQUE(x,y) // NONE

Parameters

bool $backquoted whether to quote name with backticks ``
bool $fullName whether to include full name of the table as a prefix

Return Value

array

at line 1741
array getIndexedColumns(bool $backquoted = true, bool $fullName = true)

Get all indexed columns

returns an array with all columns that make use of an index

e.g. index(col1, col2) would return col1, col2

Parameters

bool $backquoted whether to quote name with backticks ``
bool $fullName whether to include full name of the table as a prefix

Return Value

array

at line 1763
array getColumns(bool $backquoted = true, bool $fullName = true)

Get all columns

returns an array with all columns

Parameters

bool $backquoted whether to quote name with backticks ``
bool $fullName whether to include full name of the table as a prefix

Return Value

array

at line 1776
mixed getColumnsMeta()

Get meta info for fields in table

Return Value

mixed

at line 1799
array getNonGeneratedColumns(bool $backquoted = true)

Get non-generated columns in table

Parameters

bool $backquoted whether to quote name with backticks ``

Return Value

array

at line 1834
protected array getUiPrefsFromDb()

Return UI preferences for this table from phpMyAdmin database.

Return Value

array

at line 1859
protected true|Message saveUiPrefsToDb()

Save this table's UI preferences into phpMyAdmin database.

Return Value

true|Message

at line 1935
protected void loadUiPrefs()

Loads the UI preferences for this table.

If pmadb and table_uiprefs is set, it will load the UI preferences from phpMyAdmin database.

Return Value

void

at line 1962
mixed getUiProp(string $property)

Get a property from UI preferences.

Return false if the property is not found. Available property: - PROP_SORTED_COLUMN - PROP_COLUMN_ORDER - PROP_COLUMN_VISIB

Parameters

string $property property

Return Value

mixed

at line 2038
bool|Message setUiProp(string $property, mixed $value, string $table_create_time = null)

Set a property from UI preferences.

If pmadb and table_uiprefs is set, it will save the UI preferences to phpMyAdmin database. Available property: - PROP_SORTED_COLUMN - PROP_COLUMN_ORDER - PROP_COLUMN_VISIB

Parameters

string $property Property
mixed $value Value for the property
string $table_create_time Needed for PROP_COLUMN_ORDER and PROP_COLUMN_VISIB

Return Value

bool|Message

at line 2087
true|Message removeUiProp(string $property)

Remove a property from UI preferences.

Parameters

string $property the property

Return Value

true|Message

at line 2111
array getReservedColumnNames()

Get all column names which are MySQL reserved words

Return Value

array

at line 2130
array getNameAndTypeOfTheColumns()

Function to get the name and type of the columns of a table

Return Value

array

at line 2158
Index getIndex(string $index)

Get index with index name

Parameters

string $index Index name

Return Value

Index

at line 2171
string getSqlQueryForIndexCreateOrEdit(Index $index, bool $error)

Function to get the sql query for index creation or edit

Parameters

Index $index current index
bool $error whether error occurred or not

Return Value

string

at line 2283
bool updateDisplayField(string $display_field, array $cfgRelation)

Function to handle update for display field

Parameters

string $display_field display field
array $cfgRelation configuration relation

Return Value

bool True on update succeed or False on failure

at line 2328
bool updateInternalRelations(array $multi_edit_columns_name, array $destination_db, array $destination_table, array $destination_column, array $cfgRelation, array|null $existrel)

Function to get update query for updating internal relations

Parameters

array $multi_edit_columns_name multi edit column names
array $destination_db destination tables
array $destination_table destination tables
array $destination_column destination columns
array $cfgRelation configuration relation
array|null $existrel db, table, column

Return Value

bool

at line 2418
array updateForeignKeys(array $destination_foreign_db, array $multi_edit_columns_name, array $destination_foreign_table, array $destination_foreign_column, array $options_array, string $table, array $existrel_foreign)

Function to handle foreign key updates

Parameters

array $destination_foreign_db destination foreign database
array $multi_edit_columns_name multi edit column names
array $destination_foreign_table destination foreign table
array $destination_foreign_column destination foreign column
array $options_array options array
string $table current table
array $existrel_foreign db, table, column

Return Value

array

at line 2673
array|bool getColumnGenerationExpression(string $column = null)

Returns the generation expression for virtual columns

Parameters

string $column name of the column

Return Value

array|bool associative array of column name and their expressions or false on failure

at line 2727
mixed showCreate()

Returns the CREATE statement for this table

Return Value

mixed

at line 2742
int getRealRowCountTable()

Returns the real row count for a table

Return Value

int

at line 2763
array getColumnsWithIndex(int $types)

Get columns with indexes

Parameters

int $types types bitmask

Return Value

array an array of columns