Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max allowed size in Text field of MySQL

Tags:

html

php

mysql

I am doing a project where user can post text, i have used TinyText.
i need to know how much input user should be allowed to do ? i came to know TinyText allows only 255 characters to be entered from http://www.htmlite.com/mysql003.php
But if a user enters & then it have to be converted to &amp and so...
So what should be the ideal size allowed to be inputted from the users for these field/data types

TinyText
Text

User can insert data, but can not edit !
An user can view others data !
So, view will be used mostly !

like image 476
Sourav Avatar asked Apr 20 '11 12:04

Sourav


People also ask

What is maximum size of a text MySQL?

TEXT: 65,535 characters - 64 KB The standard TEXT data object is sufficiently capable of handling typical long-form text content. TEXT data objects top out at 64 KB (expressed as 2^16 -1) or 65,535 characters and requires a 2 byte overhead.

What is the maximum length a text field?

The maxlength attribute specifies the maximum number of characters that can be entered. By default, the maximum is 524,288 characters.

What is max size of VARCHAR in MySQL?

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.


2 Answers

Here you can find details about MySQL text type: http://dev.mysql.com/doc/refman/5.0/en/blob.html

like image 118
morandi3 Avatar answered Sep 28 '22 20:09

morandi3


I don't think replacing html entities and insert them into your database lets you control the final length that is inserted into your tinytext.

I'd go for 2 options.

  1. Insert raw data into the database, and use htmlentities on outputting.
  2. Restrict it to an maximum amount of characters, but use a larger text-type.

Depending on your application I'd pick one.

like image 25
Wesley van Opdorp Avatar answered Sep 28 '22 19:09

Wesley van Opdorp