PHP/MySQL : Creating a MySQL Table
Jean-Guillaume Birot
Table Template Design
MySQL provides a number of data types for representing the attributes of the object. The previous list of attributes will
then be modelled in the form of columns, as shown in the following table:
| Data
|
Column name
|
Data type
|
| Unique identification number
|
id
|
UNSIGNED SMALLINT, Auto-incremented
|
| Title
|
titre
|
VARCHAR, maximum 128 characters
|
| Author name
|
auteur
|
VARCHAR, maximum 32 characters
|
| Short introduction
|
short_intro
|
TEXT
|
| Description
|
long_intro
|
TEXT
|
| Body
|
corps
|
LONGTEXT
|
| Name of an image file
|
image
|
VARCHAR, maximum 128 characters
|
| Topic
|
theme
|
ENUM('news','music','cinema')
|
| Category
|
type
|
ENUM('interview','story','review')
|
| Date
|
date
|
DATE
|
| Yes/No type variable
|
affichage
|
ENUM('yes','no')
|
To help you understand this table better, let's examine the various types of data that are used:
- SMALLINT represents an integer between 0 and 65 535 (the UNSIGNED only permits positive numbers).

By comparison with the INT type, SMALLINT contains smaller numbers and consequently takes up less memory space. It is nevertheless sufficient for our article counter.
- VARCHAR contains text strings of variable lengths, whose maximum number of characters is known.

- TEXT is a data type for text fields containing a maximum of 64KB of text. As for LONGTEXT, it can store up to 4GB of text!

These types are useful to store a content of which you do not know the size.
- ENUM is used to define a predefined list of values accepted in a column.

All attempts at inserting an unknown value will be rejected by the MySQL server. The first two ENUM columns listed in the table allow only topics and categories as values; they can be customised. The last ENUM column acts as if it were a boolean type, accepting only one of the two values 'yes/no'.