13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Choosing Column Data Types<br />

239<br />

Table 9.7<br />

Continued<br />

TIMESTAMP[(M)] 1970-01-01 A timestamp, useful for transaction reporting.<br />

00:00:00 The display format depends on the value of M<br />

(see Table 9.8, which follows).<br />

Sometime The top of the range depends on the limit<br />

in 2037<br />

on Unix.<br />

timestamps.<br />

YEAR[(2|4)] 70–69 A year.You can specify two- or four-digit<br />

(1970–2069) format. Each has a different range, as shown.<br />

1901–2155<br />

Table 9.8 shows the possible different display types for TIMESTAMP.<br />

Table 9.8 TIMESTAMP Display Types<br />

Type Specified Display<br />

TIMESTAMP<br />

YYYYMMDDHHMMSS<br />

TIMESTAMP(14) YYYYMMDDHHMMSS<br />

TIMESTAMP(12) YYMMDDHHMMSS<br />

TIMESTAMP(10) YYMMDDHHMM<br />

TIMESTAMP(8) YYYYMMDD<br />

TIMESTAMP(6) YYMMDD<br />

TIMESTAMP(4) YYMM<br />

TIMESTAMP(2) YY<br />

String Types<br />

String types fall into three groups. First, there are plain old strings—that is, short pieces<br />

of text.These are the CHAR (fixed-length character) <strong>and</strong> VARCHAR (variable-length character)<br />

types.You can specify the width of each. Columns of type CHAR are padded with<br />

spaces to the maximum width regardless of the size of the data, whereas VARCHAR<br />

columns vary in width with the data. (Note that <strong>MySQL</strong> strips the trailing spaces from<br />

CHARs when they are retrieved <strong>and</strong> from VARCHARs when they are stored.) There is a space<br />

versus speed trade-off with these two types, which we discuss in more detail in<br />

Chapter 12.<br />

Second, there are TEXT <strong>and</strong> BLOB types.These types, which come in various sizes, are<br />

for longer text or binary data, respectively. BLOBs, or binary large objects, can hold anything<br />

you like—for example, image or sound data.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!