How can I select 'types' in a database table?


When you use the Create Table icon in the Forms Manager toolbar you can specify the 'type' for each column in the database table. For many tables the defaults will work OK but sometimes you need to be more specific. Here are some notes on selecting column types.

If your form is small then you can probably use the ChronoForms default settings which are VARCHAR(256) for most form inputs. The one exception is textarea elements where you should probably choose the TEXT type unless you know the maximum length that will be posted. For instance a VARCHAR(256) will only allow 256 characters.

If your form is long then you need to know that there is a limit to the maximum number of characters in a MySQL record of 65,535 bytes. This sounds a lot but note that UTF characters take 3 bytes so there is a maximum of around 80 columns of type VARCHAR(256).

If you need to tune your record then you should use the shortest 'safe' type for each column. So a 0/1 boolean value can go in a type BOOL; a date in a type DATE or DATETIME, a short integer in a MEDIUMINT, etc.

Strings are usually best in type VARCHAR: VARCHAR(16) is OK for a single name; VARCHAR(32) for a first and last name); VARCHAR(64) for an email and probably an URL; and so on.

There's more information on the various types in the MySQL manual here.