WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\database\mysql

class MySQLTable

Class Methods Summary

public function __construct(string$name)Creates a new instance of the class.public function addColumn(string$key, MySQLColumn$colObj)Adds new column to the table.public function addColumns(array$colsArr)Adds multiple columns at once.public function getCharSet()Returns the character set that is used by the table.public function getCollation()Returns the value of table collation.public function getEngine()Returns the name of the storage engine used by the table.public function getMySQLVersion()Returns version number of MySQL server.public function getName()Returns the name of the table.public function removeColByKey(string$key)Removes a column given its key.public function setMySQLVersion(string$vNum)Sets version number of MySQL server.public function toSQL()Returns SQL query which can be used to create the table.

Class Methods Details

public function __construct(string$name)Creates a new instance of the class. This method will initialize the basic settings of the table. It will set MySQL version to 8.0, the engine to 'InnoDB' and char set to 'utf8mb4'.

Parameters:

  • string $name The name of the table.
public function addColumn(string$key, MySQLColumn$colObj)Adds new column to the table. Note that the column will be added only if no column was found in the table which has the same name as the given column (key name and database name).

Parameters:

  • string $key The index at which the column will be added to. The name of the key can only have the following characters: [A-Z], [a-z], [0-9] and '-'.
  • MySQLColumn $colObj An object of type MySQLColumn.
Returns: booleantrue if the column is added. false otherwise.
public function addColumns(array$colsArr)Adds multiple columns at once.

Parameters:

  • array $colsArr An associative array. The keys will act as column key in the table. The value of the key can be an object of type 'MySQLColumn' or be an associative array of column options. The available options are:
    • name: The name of the column in the database. If not provided, the name of the key will be used but with every '-' replaced by '_'.
    • datatype: The datatype of the column. If not provided, 'varchar' will be used. Note that the value 'type' can be used as an alias to this index.
    • size: Size of the column (if datatype does support size). If not provided, 1 will be used.
    • default: A default value for the column if its value is not present in case of insert.
    • is-null: A boolean. If the column allows null values, this should be set to true. Default is false.
    • is-primary: A boolean. It must be set to true if the column represents a primary key. Note that the column will be set as unique once its set as a primary.
    • auto-inc: A boolean. Only applicable if the column is a primary key. Set to true to auto-increment column value by 1 for every insert.
    • is-unique: A boolean. If set to true, a unique index will be created for the column.
    • auto-update: A boolean. If the column datatype is 'timestamp' or 'datetime' and this parameter is set to true, the time of update will change automatically without having to change it manually.
    • scale: Number of numbers to the left of the decimal point. Only supported for decimal datatype.
    • comment A comment which can be used to describe the column.
public function getCharSet()Returns the character set that is used by the table. Returns: stringThe character set that is used by the table.. The default value is 'utf8'.public function getCollation()Returns the value of table collation. If MySQL version is '5.5' or lower, the method will return 'utf8mb4_unicode_ci'. Other than that, the method will return 'utf8mb4_unicode_520_ci'.Returns: stringTable collation.public function getEngine()Returns the name of the storage engine used by the table. Returns: stringThe name of the storage engine used by the table. The default value is 'InnoDB'.public function getMySQLVersion()Returns version number of MySQL server. This one is used to maintain compatibility with old MySQL servers.Returns: stringMySQL version number (such as '5.5'). If version number is not set, The default return value is '8.0'.public function getName()Returns the name of the table. Note that the method will add backticks around the name.Returns: stringThe name of the table. Default return value is 'new_table'.public function removeColByKey(string$key)Removes a column given its key.

Parameters:

Returns: booleanIf the column was removed, the method will return true. Other than that, the method will return false.
public function setMySQLVersion(string$vNum)Sets version number of MySQL server. Version number of MySQL is used to set the correct collation for the column in case of varchar or text data types. If MySQL version is '5.5' or lower, collation will be set to 'utf8mb4_unicode_ci'. Other than that, the collation will be set to 'utf8mb4_unicode_520_ci'.

Parameters:

  • string $vNum MySQL version number (such as '5.5').
public function toSQL()Returns SQL query which can be used to create the table. Returns: stringA string that represents SQL query which can be used to create the table.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024