Home >Backend Development >PHP Tutorial >SQL-TEXT, DATE and SET data types in MySQL_PHP tutorial
The fields of the MySQL data table must have a data type defined. There are about 25 options, most of which are straightforward and require no further explanation. But there are a few that need to be mentioned.
TEXT
TEXT is not a data type, although some books may say so. It should actually be "LONG VARCHAR" or "MEDIUMTEXT".
DATE
DATE data type format is YYYY-MM-DD, for example: 1999-12-08. You can easily use the date function to get the current system time in this format:
date("Y-m-d")
And, you can subtract between DATA data types to get the difference Number of days in time:
$age = ($current_date - $birthdate);
SET
Set SET is a useful data type, it It is somewhat similar to the enumeration ENUM, except that SET can save multiple values and ENUM can only save one value. Moreover, the SET type can only have a maximum of 64 predefined values, while the ENUM type can handle a maximum of 65,535 predefined values. And what if we need a collection with more than 64 values? At this time, you need to define multiple collections to solve this problem together.
Wildcard
There are two types of wildcard characters in SQL: "*" and "%". Used in different situations. For example: If you want to see all the contents of the database, you can query like this:
SELECT * FROM dbname
WHERE USER_ID LIKE '%';
Here, two wildcards are used. They mean the same thing - they both match any string - but they are used in different contexts. " * " is used to match field names, and " % " is used to match field values. Another thing that is not easy to notice is that the "%" wildcard character needs to be used together with the LIKE keyword.
There is also a wildcard character, which is the underscore "_". It has a different meaning from the above and is used to match any single character.
(T115)