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)

Constructor

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(boolean $backquoted = false)

returns table name

string
getDbName(boolean $backquoted = false)

returns database name for this table

string
getFullName(boolean $backquoted = false)

returns full name for table, including database name

bool
isEngine(array|string $engine)

Checks the storage engine used to create table

boolean
isView()

returns whether the table is actually a view

boolean
isUpdatableView()

Returns whether the table is actually an updatable view

boolean
isMerge()

Checks if this is a merge table

mixed
getStatusInfo(string $info = null, boolean $force_read = false, boolean $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.

integer
getNumRows()

Returns the info about no of rows for current table.

string
getRowFormat()

Returns the Row format for current table.

integer
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)

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|boolean
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 boolean
isValidName(string $table_name, boolean $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.

boolean|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

boolean
updateDisplayField(string $display_field, array $cfgRelation)

Function to handle update for display field

boolean
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|boolean
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 95
__construct(string $table_name, string $db_name, DatabaseInterface|null $dbi = null)

Constructor

Parameters

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

at line 112
string __toString()

returns table name

Return Value

string table name

See also

at line 126
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 136
string getLastError()

return the last error

Return Value

string the last error

at line 146
string getLastMessage()

return the last message

Return Value

string the last message

at line 158
string getName(boolean $backquoted = false)

returns table name

Parameters

boolean $backquoted whether to quote name with backticks ``

Return Value

string table name

at line 173
string getDbName(boolean $backquoted = false)

returns database name for this table

Parameters

boolean $backquoted whether to quote name with backticks ``

Return Value

string database name for this table

at line 188
string getFullName(boolean $backquoted = false)

returns full name for table, including database name

Parameters

boolean $backquoted whether to quote name with backticks ``

Return Value

string

at line 204
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 225
boolean isView()

returns whether the table is actually a view

Return Value

boolean whether the given is a view

at line 261
boolean isUpdatableView()

Returns whether the table is actually an updatable view

Return Value

boolean whether the given is an updatable view

at line 285
boolean 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

boolean true if it is a merge table

at line 303
mixed getStatusInfo(string $info = null, boolean $force_read = false, boolean $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
boolean $force_read read new rather than serving from cache
boolean $disable_error if true, disables error message

Return Value

mixed

at line 359
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 373
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 387
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 401
integer getNumRows()

Returns the info about no of rows for current table.

Return Value

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

at line 416
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 430
integer getAutoIncrement()

Returns the auto increment option for current table.

Return Value

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

at line 440
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 488
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)

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

Return Value

string field specification

at line 657
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 700
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 815
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 871
static int|boolean 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|boolean

at line 959
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 1500
static boolean isValidName(string $table_name, boolean $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
boolean $is_backquoted whether this name is used inside backquotes or not

Return Value

boolean whether the string is valid or not

See also

at line 1538
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 1646
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 1722
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 1744
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 1757
mixed getColumnsMeta()

Get meta info for fields in table

Return Value

mixed

at line 1780
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 1815
protected array getUiPrefsFromDb()

Return UI preferences for this table from phpMyAdmin database.

Return Value

array

at line 1840
protected true|Message saveUiPrefsToDb()

Save this table's UI preferences into phpMyAdmin database.

Return Value

true|Message

at line 1916
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 1943
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 2019
boolean|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

boolean|Message

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

Remove a property from UI preferences.

Parameters

string $property the property

Return Value

true|Message

at line 2091
array getReservedColumnNames()

Get all column names which are MySQL reserved words

Return Value

array

at line 2110
array getNameAndTypeOfTheColumns()

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

Return Value

array

at line 2138
Index getIndex(string $index)

Get index with index name

Parameters

string $index Index name

Return Value

Index

at line 2151
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 2263
boolean 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

boolean True on update succeed or False on failure

at line 2308
boolean 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

boolean

at line 2398
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 2653
array|boolean getColumnGenerationExpression(string $column = null)

Returns the generation expression for virtual columns

Parameters

string $column name of the column

Return Value

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

at line 2707
mixed showCreate()

Returns the CREATE statement for this table

Return Value

mixed

at line 2722
int getRealRowCountTable()

Returns the real row count for a table

Return Value

int

at line 2743
array getColumnsWithIndex(int $types)

Get columns with indexes

Parameters

int $types types bitmask

Return Value

array an array of columns