Data Type of MySQL..what we must know….!

Data type is an important factor of programming languages. People like me, who learned PHP through project or privately faced problems with this topic. In a project we don’t have to go through all the data types so that we don’t know about the rest what we didn’t use in the project. For every new PHP and MySQL learner learning data type is the most important thing. We have a lots of data type in MySQL. I do not want to go through every types but I want to discuss about BLOB, DATETIME and ENUM.

You can use a BLOB(BINARY LARGE OBJECT) data type to store any data that a program can generate: graphic images, satellite images, video clips, audio clips, or formatted documents saved by any word processor or spreadsheet. The database server permits any kind of data of any length in a BLOB column. So when you make an entity to keep the uploaded files you should use BLOB data type for this entity.

DATETIME: Although it seems using this datatype will be easy like others, actually it is not that easy for the first time user. As we know if we have any entity in our table then we take the input from the user and through ‘GET‘ or ‘POST‘ we keep it in a variable and process those variable to insert into the database. However, DATETIME will be  automatically generated. Coder’s don’t have to take it in a variable and it will take the time and date of  the server. Question is how to process it to the database?….How to do the coding part…?

Try like your INSERT coding line…

$sql="INSERT INTO `table_name` (`name`,`f_name`,`m_name`, `date_created`) VALUES ('$name', '$f_name', '$m_name', now())";

here….$name, $f_name, $m_name these three are variables which contain the values of name, f_name,m_name…..

now() is a built in function which does the trick for DATETIME…. :D.

Sometimes we need to make some user inactive…there is a way we can do that by using type into the database….if we declare that type 1 people will be active and type 2 will be inactive…..But for me it looks not good.

So instead I tried for enum datatype. When I declare enum then I give two values. One is ‘active’ another is ‘inactive’….Which makes my work easier….. 😉 ..


About Mazharul Anwar

A PHP and javascript nerd believe in web applications and open source goodness. Ex MS Windows user converted to linux fanboy and love gadgets. Coding in python and maintaining servers become my passion. Website performance and optimization geek.
This entry was posted in Programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s