PHP Class PMA\libraries\Table

Datei anzeigen Open project: phpmyadmin/phpmyadmin Class Usage Examples

Public Properties

Property Type Description
$engine engine (innodb, myisam, bdb, ...)
$errors errors occurred
$messages messages
$type type (view, base table, system view)
$uiprefs UI preferences

Protected Properties

Property Type Description
$_db_name database name
$_dbi DatabaseInterface
$_name table name

Public Methods

Method Description
__construct ( string $table_name, string $db_name, DatabaseInterface $dbi = null ) Constructor
__toString ( ) : string returns table name
checkIfMinRecordsExist ( integer $min_records ) : boolean Checks if the number of records in a table is at least equal to $min_records
countRecords ( boolean $force_exact = false ) : mixed Counts and returns (or displays) the number of records in a table
duplicateInfo ( string $work, string $pma_table, array $get_fields, array $where_fields, array $new_fields ) : integer | boolean Inserts existing entries in a PMA_* table by reading a value from an old entry
generateAlter ( string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, boolean | string $null, string $default_type, string $default_value, string $extra, string $comment, string $virtuality, string $expression, string $move_to ) : string Generates column specification for ALTER syntax
generateFieldSpec ( string $name, string $type, string $length = '', string $attribute = '', string $collation = '', boolean | string $null = false, string $default_type = 'USER_DEFINED', string $default_value = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $move_to = '' ) : string generates column specification for ALTER or CREATE TABLE syntax
getColumnGenerationExpression ( string $column = null ) : array | boolean Returns the generation expression for virtual columns
getColumns ( boolean $backquoted = true, boolean $fullName = true ) : array Get all columns
getColumnsMeta ( ) : mixed Get meta info for fields in table
getColumnsWithIndex ( integer $types ) : array Get columns with indexes
getDbName ( boolean $backquoted = false ) : string returns database name for this table
getFullName ( boolean $backquoted = false ) : string returns full name for table, including database name
getIndex ( string $index ) : Index Get index with index name
getIndexedColumns ( boolean $backquoted = true, boolean $fullName = true ) : array Get all indexed columns
getLastError ( ) : string return the last error
getLastMessage ( ) : string return the last message
getName ( boolean $backquoted = false ) : string returns table name
getNameAndTypeOfTheColumns ( ) : array Function to get the name and type of the columns of a table
getNonGeneratedColumns ( boolean $backquoted = true ) : array Get non-generated columns in table
getRealRowCountTable ( ) : number Returns the real row count for a table
getReservedColumnNames ( ) : array Get all column names which are MySQL reserved words
getSqlQueryForIndexCreateOrEdit ( Index $index, &$error ) : string Function to get the sql query for index creation or edit
getStatusInfo ( string $info = null, boolean $force_read = false, boolean $disable_error = false ) : mixed Returns full table status info, or specific if $info provided this info is collected from information_schema
getUiProp ( string $property ) : mixed Get a property from UI preferences.
getUniqueColumns ( boolean $backquoted = true, boolean $fullName = true ) : array Get all unique columns
isEngine ( $engine ) : boolean Checks the storage engine used to create table
isMerge ( ) : boolean Checks if this is a merge table
isUpdatableView ( ) : boolean Returns whether the table is actually an updatable view
isValidName ( string $table_name, boolean $is_backquoted = false ) : boolean checks if given name is a valid table name, currently if not empty, trailing spaces, '.', '/' and '\'
isView ( ) : boolean returns whether the table is actually a view
moveCopy ( string $source_db, string $source_table, string $target_db, string $target_table, string $what, boolean $move, string $mode ) : boolean Copies or renames table
removeUiProp ( string $property ) : true | Message Remove a property from UI preferences.
rename ( string $new_name, string $new_db = null ) : boolean renames table
setUiProp ( string $property, mixed $value, string $table_create_time = null ) : boolean | Message Set a property from UI preferences.
showCreate ( ) : mixed Returns the CREATE statement for this table
updateDisplayField ( string $disp, string $display_field, array $cfgRelation ) : boolean Function to handle update for display field
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 ) : array Function to handle foreign key updates
updateInternalRelations ( array $multi_edit_columns_name, array $destination_db, array $destination_table, array $destination_column, array $cfgRelation, array | null $existrel ) : boolean Function to get update query for updating internal relations

Protected Methods

Method Description
getUiPrefsFromDb ( ) : array Return UI preferences for this table from phpMyAdmin database.
loadUiPrefs ( ) : void Loads the UI preferences for this table.
saveUiPrefsToDb ( ) : true | Message Save this table's UI preferences into phpMyAdmin database.

Private Methods

Method Description
_formatColumns ( array $indexed, boolean $backquoted, boolean $fullName ) : array Formats lists of columns
_getSQLToCreateForeignKey ( string $table, array $field, string $foreignDb, string $foreignTable, array $foreignField, string $name = null, string $onDelete = null, string $onUpdate = null ) : string Returns the SQL query for foreign key constraint creation

Method Details

__construct() public method

Constructor
public __construct ( string $table_name, string $db_name, DatabaseInterface $dbi = null )
$table_name string table name
$db_name string database name
$dbi DatabaseInterface database interface for the table

__toString() public method

returns table name
See also: Table::getName()
public __toString ( ) : string
return string table name

checkIfMinRecordsExist() public method

Checks if the number of records in a table is at least equal to $min_records
public checkIfMinRecordsExist ( integer $min_records ) : boolean
$min_records integer Number of records to check for in a table
return boolean True, if at least $min_records exist, False otherwise.

countRecords() public method

Counts and returns (or displays) the number of records in a table
public countRecords ( boolean $force_exact = false ) : mixed
$force_exact boolean whether to force an exact count
return mixed the number of records if "retain" param is true, otherwise true

duplicateInfo() public static method

Inserts existing entries in a PMA_* table by reading a value from an old entry
public static duplicateInfo ( string $work, string $pma_table, array $get_fields, array $where_fields, array $new_fields ) : integer | boolean
$work string The array index, which Relation feature to check ('relwork', 'commwork', ...)
$pma_table string The array index, which PMA-table to update ('bookmark', 'relation', ...)
$get_fields array Which fields will be SELECT'ed from the old entry
$where_fields array Which fields will be used for the WHERE query (array('FIELDNAME' => 'FIELDVALUE'))
$new_fields array Which fields will be used as new VALUES. These are the important keys which differ from the old entry (array('FIELDNAME' => 'NEW FIELDVALUE'))
return integer | boolean

generateAlter() public static method

Generates column specification for ALTER syntax
See also: Table::generateFieldSpec()
public static generateAlter ( string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, boolean | string $null, string $default_type, string $default_value, string $extra, string $comment, string $virtuality, string $expression, string $move_to ) : string
$oldcol string old column name
$newcol string new column name
$type string type ('INT', 'VARCHAR', 'BIT', ...)
$length string length ('2', '5,2', '', ...)
$attribute string attribute
$collation string collation
$null boolean | string with 'NULL' or 'NOT NULL'
$default_type string whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED
$default_value string default value for USER_DEFINED default type
$extra string 'AUTO_INCREMENT'
$comment string field comment
$virtuality string virtuality of the column
$expression string expression for the virtual column
$move_to string new position for column
return string field specification

generateFieldSpec() static public method

generates column specification for ALTER or CREATE TABLE syntax
static public generateFieldSpec ( string $name, string $type, string $length = '', string $attribute = '', string $collation = '', boolean | string $null = false, string $default_type = 'USER_DEFINED', string $default_value = '', string $extra = '', string $comment = '', string $virtuality = '', string $expression = '', string $move_to = '' ) : string
$name string name
$type string type ('INT', 'VARCHAR', 'BIT', ...)
$length string length ('2', '5,2', '', ...)
$attribute string attribute
$collation string collation
$null boolean | string with 'NULL' or 'NOT NULL'
$default_type string whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED
$default_value string default value for USER_DEFINED default type
$extra string 'AUTO_INCREMENT'
$comment string field comment
$virtuality string virtuality of the column
$expression string expression for the virtual column
$move_to string new position for column
return string field specification

getColumnGenerationExpression() public method

Returns the generation expression for virtual columns
public getColumnGenerationExpression ( string $column = null ) : array | boolean
$column string name of the column
return array | boolean associative array of column name and their expressions or false on failure

getColumns() public method

returns an array with all columns
public getColumns ( boolean $backquoted = true, boolean $fullName = true ) : array
$backquoted boolean whether to quote name with backticks ``
$fullName boolean whether to include full name of the table as a prefix
return array

getColumnsMeta() public method

Get meta info for fields in table
public getColumnsMeta ( ) : mixed
return mixed

getColumnsWithIndex() public method

Get columns with indexes
public getColumnsWithIndex ( integer $types ) : array
$types integer types bitmask
return array an array of columns

getDbName() public method

returns database name for this table
public getDbName ( boolean $backquoted = false ) : string
$backquoted boolean whether to quote name with backticks ``
return string database name for this table

getFullName() public method

returns full name for table, including database name
public getFullName ( boolean $backquoted = false ) : string
$backquoted boolean whether to quote name with backticks ``
return string

getIndex() public method

Get index with index name
public getIndex ( string $index ) : Index
$index string Index name
return Index

getIndexedColumns() public method

returns an array with all columns that make use of an index e.g. index(col1, col2) would return col1, col2
public getIndexedColumns ( boolean $backquoted = true, boolean $fullName = true ) : array
$backquoted boolean whether to quote name with backticks ``
$fullName boolean whether to include full name of the table as a prefix
return array

getLastError() public method

return the last error
public getLastError ( ) : string
return string the last error

getLastMessage() public method

return the last message
public getLastMessage ( ) : string
return string the last message

getName() public method

returns table name
public getName ( boolean $backquoted = false ) : string
$backquoted boolean whether to quote name with backticks ``
return string table name

getNameAndTypeOfTheColumns() public method

Function to get the name and type of the columns of a table
public getNameAndTypeOfTheColumns ( ) : array
return array

getNonGeneratedColumns() public method

Get non-generated columns in table
public getNonGeneratedColumns ( boolean $backquoted = true ) : array
$backquoted boolean whether to quote name with backticks ``
return array

getRealRowCountTable() public method

Returns the real row count for a table
public getRealRowCountTable ( ) : number
return number

getReservedColumnNames() public method

Get all column names which are MySQL reserved words
public getReservedColumnNames ( ) : array
return array

getSqlQueryForIndexCreateOrEdit() public method

Function to get the sql query for index creation or edit
public getSqlQueryForIndexCreateOrEdit ( Index $index, &$error ) : string
$index Index current index
return string

getStatusInfo() public method

Returns full table status info, or specific if $info provided this info is collected from information_schema
public getStatusInfo ( string $info = null, boolean $force_read = false, boolean $disable_error = false ) : mixed
$info string specific information to be fetched
$force_read boolean read new rather than serving from cache
$disable_error boolean if true, disables error message
return mixed

getUiPrefsFromDb() protected method

Return UI preferences for this table from phpMyAdmin database.
protected getUiPrefsFromDb ( ) : array
return array

getUiProp() public method

Return false if the property is not found. Available property: - PROP_SORTED_COLUMN - PROP_COLUMN_ORDER - PROP_COLUMN_VISIB
public getUiProp ( string $property ) : mixed
$property string property
return mixed

getUniqueColumns() public method

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
public getUniqueColumns ( boolean $backquoted = true, boolean $fullName = true ) : array
$backquoted boolean whether to quote name with backticks ``
$fullName boolean whether to include full name of the table as a prefix
return array

isEngine() public method

Checks the storage engine used to create table
public isEngine ( $engine ) : boolean
return boolean True, if $engine matches the storage engine for the table, False otherwise.

isMerge() public method

If the ENGINE of the table is MERGE or MRG_MYISAM (alias), this is a merge table.
public isMerge ( ) : boolean
return boolean true if it is a merge table

isUpdatableView() public method

Returns whether the table is actually an updatable view
public isUpdatableView ( ) : boolean
return boolean whether the given is an updatable view

isValidName() static public method

checks if given name is a valid table name, currently if not empty, trailing spaces, '.', '/' and '\'
See also: https://dev.mysql.com/doc/refman/5.0/en/legal-names.html
static public isValidName ( string $table_name, boolean $is_backquoted = false ) : boolean
$table_name string name to check
$is_backquoted boolean whether this name is used inside backquotes or not
return boolean whether the string is valid or not

isView() public method

returns whether the table is actually a view
public isView ( ) : boolean
return boolean whether the given is a view

loadUiPrefs() protected method

If pmadb and table_uiprefs is set, it will load the UI preferences from phpMyAdmin database.
protected loadUiPrefs ( ) : void
return void

moveCopy() public static method

Copies or renames table
public static moveCopy ( string $source_db, string $source_table, string $target_db, string $target_table, string $what, boolean $move, string $mode ) : boolean
$source_db string source database
$source_table string source table
$target_db string target database
$target_table string target table
$what string what to be moved or copied (data, dataonly)
$move boolean whether to move
$mode string mode
return boolean true if success, false otherwise

removeUiProp() public method

Remove a property from UI preferences.
public removeUiProp ( string $property ) : true | Message
$property string the property
return true | Message

rename() public method

renames table
public rename ( string $new_name, string $new_db = null ) : boolean
$new_name string new table name
$new_db string new database name
return boolean success

saveUiPrefsToDb() protected method

Save this table's UI preferences into phpMyAdmin database.
protected saveUiPrefsToDb ( ) : true | Message
return true | Message

setUiProp() public method

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
public setUiProp ( string $property, mixed $value, string $table_create_time = null ) : boolean | Message
$property string Property
$value mixed Value for the property
$table_create_time string Needed for PROP_COLUMN_ORDER and PROP_COLUMN_VISIB
return boolean | Message

showCreate() public method

Returns the CREATE statement for this table
public showCreate ( ) : mixed
return mixed

updateDisplayField() public method

Function to handle update for display field
public updateDisplayField ( string $disp, string $display_field, array $cfgRelation ) : boolean
$disp string current display field
$display_field string display field
$cfgRelation array configuration relation
return boolean True on update succeed or False on failure

updateForeignKeys() public method

Function to handle foreign key updates
public 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 ) : array
$destination_foreign_db array destination foreign database
$multi_edit_columns_name array multi edit column names
$destination_foreign_table array destination foreign table
$destination_foreign_column array destination foreign column
$options_array array options array
$table string current table
$existrel_foreign array db, table, column
return array

updateInternalRelations() public method

Function to get update query for updating internal relations
public updateInternalRelations ( array $multi_edit_columns_name, array $destination_db, array $destination_table, array $destination_column, array $cfgRelation, array | null $existrel ) : boolean
$multi_edit_columns_name array multi edit column names
$destination_db array destination tables
$destination_table array destination tables
$destination_column array destination columns
$cfgRelation array configuration relation
$existrel array | null db, table, column
return boolean

Property Details

$_db_name protected_oe property

database name
protected $_db_name

$_dbi protected_oe property

protected DatabaseInterface,PMA\libraries $_dbi
return DatabaseInterface

$_name protected_oe property

table name
protected $_name

$engine public_oe property

engine (innodb, myisam, bdb, ...)
public $engine

$errors public_oe property

errors occurred
public $errors

$messages public_oe property

messages
public $messages

$type public_oe property

type (view, base table, system view)
public $type

$uiprefs public_oe property

UI preferences
public $uiprefs