phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP MySQL: The Data Type of Field

Tag: mysql, database, field, data type   Category: PHP Database
post: 28 Feb 2008 read: 1,306


php mysql basic step by step tutorial - part 4: There are some type of MySQL field data, such as:

Numeric data type

It differentiates into two kinds of group, there are integer and floating point data type. For the most information of numeric data type, you just take a look at the table beneath:

Data type Gyration assess
TINYINT (-128) - 127 or 0 - 255
SMALLINT (-32768) - 32767 or 0 - 65535
MEDIUMINT (-8388608) - 8388607 or 0 - 16777215
INT (-2147683648) - 2147683647 or 0 - 4294967295
BIGINT (-9223372036854775808) - 9223372036854775807 or 0 - 18446744073709551615
FLOAT(X) (-3.402823466E+38) - (-1.175494351E-38), 0, and 1.175494351E-38 - 3.402823466E+38.
FLOAT The same as above
DOUBLE (-1.7976931348623157E+308) - (-2.2250738585072014E-308), 0, and 2.2250738585072014E-308 - 1.7976931348623157E+308

Those data type needs memory requirement as follows:

Data type Memory requirement needs
TINYINT 1 byte
SMALLINT 2 bytes
MEDIUMINT 3 bytes
INT 4 bytes
INTEGER 4 bytes
BIGINT 8 bytes
FLOAT(X) 4 ifX <=24 or 8 if 25 <=X <=53
FLOAT 4 bytes
DOUBLE 8 bytes
DOUBLE PRECISION 8 bytes
REAL 8 bytes
DECIMAL(M,D) M+2 bytes if D>0, M+1 bytes if D=0(D+2, if M
NUMERIC(M,D) M+2 bytes if D>0, M+1 bytes if D=0(D+2, if M

String data type

The types of data that is included into String data such as:

Data type Gyration assess
CHAR 1-255 character
VARCHAR 1-255 character
TINYLOB, TINYTEXT 1-255 character
BLOB, TEXT 1-65535 character
MEDIUMLOB, MEDIUMTEXT 1-16777215 character
LONGLOB, LONGTEXT 1-4294967295 character
ENUM('element1','element2',...) Maximal 65535 character
SET('element1','element2',...) Maximal 64 element

Those data type needs memory requirement as follows:

Data type Memory requirement needs
CHAR(M) M bytes, 1 <=M <=255
VARCHAR(M) L+1 bytes, L <=M and 1 <=M <=255
TINYLOB, TINYTEXT L+1 bytes, L <2^8
BLOB, TEXT L+2 bytes, L<2^16
MEDIUMLOB, MEDIUMTEXT L+3 bytes, L<2^24
LONGBLOB, LONGTEXT L+4 bytes, L<2^32
ENUM('element1','element2',...) 1 or 2 bytes, depend to the number of element
SET('element1','element2',...) 1, 2, 3, 4 or 8 bytes, depend to the number of element


Series this article:
PHP MySQL: Connecting to Database Use mysql_connect()
PHP MySQL: Making Database Use mysql_create_db()
PHP MySQL: Making Table
PHP MySQL: The Data Type of Field
PHP MySQL: Char and Varchar Data Type
PHP MySQL: Data Type of Date
PHP MySQL: MySQL Syntax Orders
PHP MySQL: Inserting Data
PHP MySQL: Creating Form Insert Data
PHP MySQL: Display Data
PHP MySQL: mysql_fetch_row() Function
PHP MySQL: mysql_fetch_array() Function
PHP MySQL: Editing data
PHP MySQL: Deleting data
PHP MySQL: Adding Field Table
PHP MySQL: Editing Field Table
PHP MySQL: Deleting Field Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting