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 MySQLColumn

Class Methods Summary

public function __construct(string$name, string$datatype, int$size)Creates new instance of the class.public function __toString()Constructs a string that can be used to create the column in a table.public function asString()Returns a string that represents the column.public function cleanValue(mixed$val)Validates and cleans a value for usage in a query.public static function createColObj(array$options)Creates an instance of the class 'Column' given an array of options.public function getAlias()Returns column alias.public function getCollation()Returns the value of column collation.public function getDefault()Returns the default value of the column.public function getMySQLVersion()Returns version number of MySQL server.public function getName()Returns the name of the column.public function getPHPType()Returns a string that represents the datatype of column data in PHP.public function isAutoInc()Checks if the column is auto increment or not.public function isAutoUpdate()Returns the value of the property 'isAutoUpdate'.public function setAutoUpdate(boolean$bool)Sets the value of the property 'isAutoUpdate'.public function setDatatype(string$type)Sets the datatype of the column.public function setDefault(mixed$default)Sets the default value for the column to use in case of insert.public function setIsAutoInc(boolean$bool)Sets the value of the property $isAutoInc.public function setIsPrimary(boolean$bool)Makes the column primary or not.public function setMySQLVersion(string$vNum)Sets version number of MySQL server.public function setOwner(MySQLTable|null$table)Sets or unset the owner table of the column.public function setScale(int$val)Sets the value of Scale.public function setSize(int$size)Sets the size of data (for numercal types and 'varchar' only).

Class Methods Details

public function __construct(string$name, string$datatype, int$size)Creates new instance of the class. This method is used to initialize basic attributes of the column. First of all, it sets MySQL version number to 8.0. Then it initializes the supported datatypes.

Parameters:

  • string $name The name of the column as it appears in the database. It must be a string and its not empty. Default value is 'col'.
  • string $datatype The type of column data. Default value is 'varchar'.
  • int $size The size of the column. Used only in case of 'varachar', 'int' or decimal. If the given size is invalid, 1 will be used as default value.
public function __toString()Constructs a string that can be used to create the column in a table. Returns: stringA string that can be used to create the column in a table.public function asString()Returns a string that represents the column. The string can be used to add the column to a table or alter its properties.Returns: string public function cleanValue(mixed$val)Validates and cleans a value for usage in a query.

Parameters:

  • mixed $val The value that will be cleaned.
Returns: mixedThe method will return a value which is based on applied filters and the datatype of the column.
public static function createColObj(array$options)Creates an instance of the class 'Column' given an array of options.

Parameters:

  • array $options An associative array of options. The available options are:
    • name: Required. The name of the column in the database. If not provided, no object will be created.
    • datatype: The datatype of the column. If not provided, 'varchar' will be used. Equal option: 'type'.
    • 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. Equal option: 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.
    • validator: A PHP function which can be used to validate user values before submitting the query to database.
Returns: MySQLColumn|nullThe method will return an object of type 'MySQLColumn' if created. If the index 'name' is not set, the method will return null.
public function getAlias()Returns column alias. Note that the method will add backticks around the alias.Returns: string|nullName alias.public function getCollation()Returns the value of column collation. Returns: stringIf 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'.public function getDefault()Returns the default value of the column. Note that for 'datetime' and 'timestamp', if default value is set to 'now()' or 'current_timestamp', the method will return a date string in the format 'YYYY-MM-DD HH:MM:SS' that represents current time.Returns: mixedThe default value of the column.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 column. Note that the method will add backticks around the name.Returns: stringThe name of the column.public function getPHPType()Returns a string that represents the datatype of column data in PHP. This method basically maps the data that can be stored in a column from MySQL type to PHP type. For example, if column type is 'varchar', the method will return the value 'string'. If the column allow null values, the method will return 'string|null' and so on.Returns: stringA string that represents column type in PHP (such as 'integer' or 'boolean').public function isAutoInc()Checks if the column is auto increment or not. Returns: booleantrue if the column is auto increment.public function isAutoUpdate()Returns the value of the property 'isAutoUpdate'. Returns: booleanIf the column type is 'datetime' or 'timestamp' and the column is set to auto update in case of update query, the method will return true. Default return value is valse.public function setAutoUpdate(boolean$bool)Sets the value of the property 'isAutoUpdate'. It is used in case the user want to update the date of a column that has the type 'datetime' or 'timestamp' automatically if a record is updated. This method has no effect for other datatypes.

Parameters:

  • boolean $bool If true is passed, then the value of the column will be updated in case an update query is constructed.
public function setDatatype(string$type)Sets the datatype of the column.

Parameters:

  • string $type A string that represents the datatype of the column.
public function setDefault(mixed$default)Sets the default value for the column to use in case of insert. For integer data type, the passed value must be an integer. For string types such as 'varchar' or 'text', the passed value must be a string. If the datatype is 'timestamp', the default will be set to current time and date if non-null value is passed (the value which is returned by the function date('Y-m-d H:i:s). If the passed value is a date string in the format 'YYYY-MM-DD HH:MM:SS', then it will be set to the given value. If the passed value is a date string in the format 'YYYY-MM-DD', then the default will be set to 'YYYY-MM-DD 00:00:00'. same applies to 'datetime' datatype. If null is passed, it implies that no default value will be used.

Parameters:

  • mixed $default The default value which will be set.
public function setIsAutoInc(boolean$bool)
Sets the value of the property $isAutoInc. This attribute can be set only if the column is primary key and the datatype of the column is set to 'int'.

Parameters:

Returns: booleantrue if the property value changed. false otherwise.
public function setIsPrimary(boolean$bool)Makes the column primary or not. Note that once the column become primary, it becomes unique by default. Also, Note that if column type is 'boolean', it cannot be a primary.

Parameters:

  • boolean $bool true if the column is primary key. false if not.
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 setOwner(MySQLTable|null$table)Sets or unset the owner table of the column. Note that the developer should not call this method manually. It is used only if the column is added or removed from MySQLTable object.

Parameters:

  • MySQLTable|null $table The owner of the column. If null is given, The owner will be unset.
public function setScale(int$val)Sets the value of Scale. Scale is simply the number of digits that will appear to the right of decimal point. Only applicable if the datatype of the column is decimal, float and double.

Parameters:

  • int $val Number of numbers after the decimal point. It must be a positive number.
Returns: booleanIf scale value is set, the method will return true. false otherwise. The method will not set the scale in the following cases:
  • Datatype of the column is not decimal, float or double.
  • Size of the column is 0.
  • Given scale value is greater than the size of the column.
public function setSize(int$size)Sets the size of data (for numercal types and 'varchar' only). If the data type of the column is 'int', the maximum size is 11. If a number greater than 11 is given, the value will be set to 11. The maximum size for the 'varchar' is 21845. If a value greater that that is given, the datatype of the column will be changed to 'mediumtext'. For decimal, double and float data types, the value will represent the precision. If zero is given, then no specific value for precision and scale will be used. If the datatype is boolean, the passed value will be ignored and the size is set to 1.

Parameters:

  • int $size The size to set.
Returns: booleantrue if the size is set. The method will return false in case the size is invalid or datatype does not support size attribute. Also The method will return false in case the datatype of the column does not support size.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024