top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between char and varchar data types in PHP?

+1 vote
1,046 views
What is the difference between char and varchar data types in PHP?
posted May 28, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

+1 vote

PHP does not have a concept of variable type, I am assuming that your query is about the MySQL CHAR/VARCHAR variable.

CHAR is a fixed length data type. CHAR(100) will take 100 characters of storage even if you enter less than 100 characters to that column.

VARCHAR is a variable length data type. VARCHAR(100) will take only the required storage for the actual number of characters entered to that column. For example, "QueryHome" will be stored as "QueryHome" in VARCHAR(100) column and will occupy 8 bytes in storage (loosely saying).

answer May 28, 2014 by Salil Agrawal
+1 vote

CHAR

Used to store character string value of fixed length.

The maximum no. of characters the data type can hold is 255 characters.

It's 50% faster than VARCHAR.

VARCHAR

Used to store variable length alphanumeric data.

The maximum this data type can hold is up to 4000 characters.

Slow in speed

As it is dynamic memory allocation type, variable length varies according to the requirement of the user.
Means user can enter more than 400 values even if the size is less according to it.

answer Aug 13, 2014 by anonymous
0 votes

Char is a fixed data type which occupies the full space irrespective of the characters entered into that particular column(or variable).
Whereas Varchar is a data type of variable length which adjusts itself automatically according to the characters entered into the column.

answer May 29, 2014 by Sachin Dahda
0 votes

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.

VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.

answer May 29, 2014 by Vrije Mani Upadhyay
...