TEXT or VARCHAR

Which is best? Put simply, use a VARCHAR field instead of TEXT for columns between 255 and 65k characters if possible as it will lead to potentially fewer disk reads and less writes. VARCHAR Max size of 65535 characters Uses 2+n bytes to store the value where n is the length of the stored string. […]

Read More

Text fields

Convert textarea ready to store in text column with line breaks etc \n new line characters will still be stored as \n (htmlspecialchars() doens’t convert them to <br>) Convert \n character to <br> when displaying Not needed for a text area (it will respect \n character) but nl2br() is needed when displaying as a general […]

Read More

DateTime general

ORDER BY Date Order ASC = oldest first DESC = most recent first Note it’s “MINUTE”, “HOUR”, etc not “MINUTES” or “HOURS” etc Convert DateTime to Date Specifying Date and DateTime from a string It is recommended to use CAST() Last Day Of Month (This produces a DATE result, not DATETIME) Get SQL Server’s Current […]

Read More

Columns Data Types

Quick Data Types List (For a more in depth description see below) Numeric BOOL Use TINYINT BIT The BIT data type is used to store bit-field values. A type of BIT(M) enables storage of M-bit values. M can range from 1 to 64.  (Not universally supported) INT A normal-sized integer that can be signed or unsigned. […]

Read More