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.

236 Chapter 9 Creating Your <strong>Web</strong> Database<br />

Table 9.4 <strong>MySQL</strong> Identifiers<br />

Type Max Case Characters<br />

Length Sensitive? Allowed<br />

Database 64 same as OS Anything allowed in a directory name in your<br />

OS except the /, \, <strong>and</strong> . characters<br />

Table 64 same as OS Anything allowed in a filename in your OS<br />

except the / <strong>and</strong> . characters<br />

Column 64 no Anything<br />

Index 64 no Anything<br />

Alias 255 no Anything<br />

These rules are extremely open.You can even have reserved words <strong>and</strong> special characters<br />

of all kinds in identifiers.The only limitation is that if you use anything unusual like this,<br />

you have to put it in backticks (located under the tilde key on the top left of most keyboards).<br />

For example,<br />

create database `create database`;<br />

Of course, you should apply common sense to all this freedom. Just because you can<br />

call a database `create database` doesn’t that mean that you should.The same principle<br />

applies here as in any other kind of programming: Use meaningful identifiers.<br />

Choosing Column Data Types<br />

The three basic column types in <strong>MySQL</strong> are numeric, date <strong>and</strong> time, <strong>and</strong> string.Within<br />

each of these categories are a large number of types.We summarize them here <strong>and</strong> go<br />

into more detail about the strengths <strong>and</strong> weaknesses of each in Chapter 12.<br />

Each of the three types comes in various storage sizes.When you are choosing a column<br />

type, the principle is generally to choose the smallest type that your data will fit<br />

into.<br />

For many data types, when you are creating a column of that type, you can specify<br />

the maximum display length.This is shown in the following tables of data types as M.If<br />

it’s optional for that type, it is shown in square brackets.The maximum value you can<br />

specify for M is 255.<br />

Optional values throughout these descriptions are shown in square brackets.<br />

Numeric Types<br />

The numeric types are either integers or floating-point numbers. For the floating-point<br />

numbers, you can specify the number of digits after the decimal place.This value is<br />

shown in this book as D.The maximum value you can specify for D is 30 or M-2 (that is,<br />

the maximum display length minus two—one character for a decimal point <strong>and</strong> one for<br />

the integral part of the number), whichever is lower.

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

Saved successfully!

Ooh no, something went wrong!