class Table implements Stringable (View source)

Handles everything related to tables

make use of Message and Error

Constants

PROP_SORTED_COLUMN

UI preferences properties

PROP_COLUMN_ORDER

PROP_COLUMN_VISIB

Properties

array $uiprefs
array $errors
array $messages

Methods

__construct(string $name, string $dbName, DatabaseInterface $dbi)

No description

string
__toString()

returns table name

static Table
get(string $tableName, string $dbName, DatabaseInterface $dbi)

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

array|string|int|null
getStatusInfo(string|null $info = null)

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.

string
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 $defaultType = 'USER_DEFINED', string $defaultValue = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $moveTo = '', array|null $columnsWithIndex = null, string|null $oldColumnName = null)

generates column specification for ALTER or CREATE TABLE syntax

bool
checkIfMinRecordsExist(int $minRecords = 0)

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

int
countRecords(bool $forceExact = false)

Counts 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 $defaultType, string $defaultValue, string $extra, string $comment, string $virtuality, string $expression, string $moveTo, array|null $columnsWithIndex = null)

Generates column specification for ALTER syntax

static int|bool
duplicateInfo(string $work, string $table, array $getFields, array $whereFields, array $newFields)

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

static bool
moveCopy(string $sourceDb, string $sourceTable, string $targetDb, string $targetTable, string $what, bool $move, string $mode, bool $addDropIfExists)

Copies or renames table

static bool
isValidName(string $tableName, bool $isBackquoted = false)

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

bool
rename(string $newName, string|null $newDb = 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

array
getColumnsMeta()

Get meta info for fields in table

array
getNonGeneratedColumns(bool $backquoted = true)

Get non-generated columns in table

array
getUiPrefsFromDb(UiPreferencesFeature|null $uiPreferencesFeature)

Return UI preferences for this table from phpMyAdmin database.

Message
saveUiPrefsToDb(UiPreferencesFeature $uiPreferencesFeature)

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.

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

Set a property from UI preferences.

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

void
updateDisplayField(string $displayField, DisplayFeature $displayFeature)

Function to handle update for display field

bool
updateInternalRelations(array $multiEditColumnsName, array $destinationDb, array $destinationTable, array $destinationColumn, RelationFeature $relationFeature, array|null $existrel)

Function to get update query for updating internal relations

array
updateForeignKeys(array $destinationForeignDb, array $multiEditColumnsName, array $destinationForeignTable, array $destinationForeignColumn, array $optionsArray, string $table, array $existrelForeign)

Function to handle foreign key updates

array|bool
getColumnGenerationExpression(string|null $column = null)

Returns the generation expression for virtual columns

string
showCreate()

Returns the CREATE statement for this table

int|null
getRealRowCountTable()

Returns the real row count for a table

array
getColumnsWithIndex(int $types)

Get columns with indexes

Details

__construct(string $name, string $dbName, DatabaseInterface $dbi)

No description

Parameters

string $name

table name

string $dbName

database name

DatabaseInterface $dbi

database interface for the table

string __toString()

returns table name

Return Value

string

See also

Table::getName

static Table get(string $tableName, string $dbName, DatabaseInterface $dbi)

Table getter

Parameters

string $tableName

table name

string $dbName

database name

DatabaseInterface $dbi

database interface for the table

Return Value

Table

string getLastError()

return the last error

Return Value

string

the last error

string getLastMessage()

return the last message

Return Value

string

the last message

string getName(bool $backquoted = false)

returns table name

Parameters

bool $backquoted

whether to quote name with backticks ``

Return Value

string

table name

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

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

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

bool isView()

returns whether the table is actually a view

Return Value

bool

bool isUpdatableView()

Returns whether the table is actually an updatable view

Return Value

bool

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

array|string|int|null getStatusInfo(string|null $info = null)

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

Parameters

string|null $info

specific information to be fetched

Return Value

array|string|int|null

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.

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.

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.

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.

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.

string getAutoIncrement()

Returns the auto increment option for current table.

Return Value

string

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

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.

static string generateFieldSpec(string $name, string $type, string $length = '', string $attribute = '', string $collation = '', bool|string $null = false, string $defaultType = 'USER_DEFINED', string $defaultValue = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $moveTo = '', array|null $columnsWithIndex = null, string|null $oldColumnName = null)

generates column specification for ALTER or CREATE TABLE syntax

move into class PMA_Column on the interface, some js to clear the default value when the default current_timestamp is checked

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 $defaultType

whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED, UUID

string $defaultValue

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 $moveTo

new position for column

array|null $columnsWithIndex

Fields having PRIMARY or UNIQUE KEY indexes

string|null $oldColumnName

Old column name

Return Value

string

field specification

bool checkIfMinRecordsExist(int $minRecords = 0)

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

Parameters

int $minRecords

Number of records to check for in a table

Return Value

bool

int countRecords(bool $forceExact = false)

Counts the number of records in a table

Parameters

bool $forceExact

whether to force an exact count

Return Value

int

static string generateAlter(string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, bool|string $null, string $defaultType, string $defaultValue, string $extra, string $comment, string $virtuality, string $expression, string $moveTo, array|null $columnsWithIndex = 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 $defaultType

whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED

string $defaultValue

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 $moveTo

new position for column

array|null $columnsWithIndex

Fields having PRIMARY or UNIQUE KEY indexes

Return Value

string

field specification

See also

Table::generateFieldSpec

static int|bool duplicateInfo(string $work, string $table, array $getFields, array $whereFields, array $newFields)

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 $table

The array index, which PMA-table to update ('bookmark', 'relation', ...)

array $getFields

Which fields will be SELECT'ed from the old entry

array $whereFields

Which fields will be used for the WHERE query (array('FIELDNAME' => 'FIELDVALUE'))

array $newFields

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

static bool moveCopy(string $sourceDb, string $sourceTable, string $targetDb, string $targetTable, string $what, bool $move, string $mode, bool $addDropIfExists)

Copies or renames table

Parameters

string $sourceDb

source database

string $sourceTable

source table

string $targetDb

target database

string $targetTable

target table

string $what

what to be moved or copied (data, dataonly)

bool $move

whether to move

string $mode mode
bool $addDropIfExists

Return Value

bool

static bool isValidName(string $tableName, bool $isBackquoted = false)

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

add check for valid chars in filename on current system/os

Parameters

string $tableName

name to check

bool $isBackquoted

whether this name is used inside backquotes or not

Return Value

bool

See also

https://dev.mysql.com/doc/refman/5.0/en/legal-names.html

bool rename(string $newName, string|null $newDb = null)

renames table

Parameters

string $newName

new table name

string|null $newDb

new database name

Return Value

bool

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

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

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

array getColumnsMeta()

Get meta info for fields in table

Return Value

array

array getNonGeneratedColumns(bool $backquoted = true)

Get non-generated columns in table

Parameters

bool $backquoted

whether to quote name with backticks ``

Return Value

array

protected array getUiPrefsFromDb(UiPreferencesFeature|null $uiPreferencesFeature)

Return UI preferences for this table from phpMyAdmin database.

Parameters

UiPreferencesFeature|null $uiPreferencesFeature

Return Value

array

protected Message saveUiPrefsToDb(UiPreferencesFeature $uiPreferencesFeature)

Save this table's UI preferences into phpMyAdmin database.

Parameters

UiPreferencesFeature $uiPreferencesFeature

Return Value

Message

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

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

Message setUiProp(string $property, mixed $value, string|null $tableCreateTime = 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|null $tableCreateTime

Needed for PROP_COLUMN_ORDER and PROP_COLUMN_VISIB

Return Value

Message

Message removeUiProp(string $property)

Remove a property from UI preferences.

Parameters

string $property

the property

Return Value

Message

array getReservedColumnNames()

Get all column names which are MySQL reserved words

Return Value

array

array getNameAndTypeOfTheColumns()

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

Return Value

array

Index getIndex(string $index)

Get index with index name

Parameters

string $index

Index name

Return Value

Index

void updateDisplayField(string $displayField, DisplayFeature $displayFeature)

Function to handle update for display field

Parameters

string $displayField

display field

DisplayFeature $displayFeature

Return Value

void

bool updateInternalRelations(array $multiEditColumnsName, array $destinationDb, array $destinationTable, array $destinationColumn, RelationFeature $relationFeature, array|null $existrel)

Function to get update query for updating internal relations

Parameters

array $multiEditColumnsName

multi edit column names

array $destinationDb

destination tables

array $destinationTable

destination tables

array $destinationColumn

destination columns

RelationFeature $relationFeature
array|null $existrel

db, table, column

Return Value

bool

array updateForeignKeys(array $destinationForeignDb, array $multiEditColumnsName, array $destinationForeignTable, array $destinationForeignColumn, array $optionsArray, string $table, array $existrelForeign)

Function to handle foreign key updates

Parameters

array $destinationForeignDb

destination foreign database

array $multiEditColumnsName

multi edit column names

array $destinationForeignTable

destination foreign table

array $destinationForeignColumn

destination foreign column

array $optionsArray

options array

string $table

current table

array $existrelForeign

db, table, column

Return Value

array

array|bool getColumnGenerationExpression(string|null $column = null)

Returns the generation expression for virtual columns

Parameters

string|null $column

name of the column

Return Value

array|bool

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

string showCreate()

Returns the CREATE statement for this table

Return Value

string

int|null getRealRowCountTable()

Returns the real row count for a table

Return Value

int|null

array getColumnsWithIndex(int $types)

Get columns with indexes

Parameters

int $types

types bitmask

Return Value

array

an array of columns