Everything PHP: MySQL Field Types

Published on Jun 24, 2009   //  Development
Off

Everything PHP

With MySQL, there are a variety of different types of fields. These types of fields correlate to the type of data that will be stored within them. By defining what type of data you will be storing within a field, you give MySQL a better idea of how to handle queries to this data, and you also open up some other possibilities within MySQL.

There are a couple of different categories of types: numeric, date and time and string. Numeric types of data include things such as integers, floats, decimals and boolean values. Date and time types are special MySQL formatted fields that can include the date, the date and time, a unix timestamp (in a MySQL format) or a year. String data fields include text, “blobs”, specific sets of possible values, variable characters strings and more.

There are far to many different types to be able to define them all here. However, the MySQL Reference Manual has some extensive documentation of data types, which is a good place to start learning about them. Once have learned the different data types, you can then factor them into your database structure plan.

Next week we’ll be taking our database structure and making it into a database. We’ll use what we’ve learned about proper structures and data field types to create our efficient and expandable database.