0

I have been asked to add functionality and fix known bugs on a web app(php, jquery, html) that hits a MySQL database. I noticed that several admin pages were not updating properly. Specifically, the text that was being entered was being cut off at around 20 characters. After doing some checking on the code, the database routines, and the database field to make sure there were no character limits(the field was declared VARCHAR(60) I believe), I decided to see what would happen if I changed the field to type TEXT. And it started working!

So that problem is fixed, however, I then read that type TEXT is depreciated and it is recommended to use type VARCHAR. So the question is, do I just leave it as type TEXT and not worry about it, or do I work on getting it to work as VARCHAR, and does anyone know why VARCHAR is acting up?

Jake Sellers
  • 2,350
  • 2
  • 21
  • 40
  • Does the content contain any special characters that might be getting converted into multi-byte? That would pad out the string longer, though I think it would have to be in some kind of kanji to go from 20 chars to 60+ – Adrian Apr 01 '13 at 17:44
  • 2
    @JakeSellers "TEXT is depreciated" -> not in MYSQL RDBMS – swapnesh Apr 01 '13 at 17:51
  • It did originally, so I took out all tick marks and such to test and it was still cutting off. – Jake Sellers Apr 01 '13 at 17:54
  • @Adrian: `VARCHAR` length parameters are specified in *characters* not bytes, so the encoding shouldn't make any difference. – eggyal Apr 01 '13 at 17:55
  • 1
    It can make a difference if the encoding is *wrong*, however. E.g., if the encoding is latin1, and you dump in a bunch of 3-byte UTF8 characters, they will be munged and take up extra characters. – Adrian Apr 01 '13 at 17:56
  • @swapnesh Ah I see, thanks for catching that. I won't worry about it for now, as it works, still curious about varchar acting up though. – Jake Sellers Apr 01 '13 at 17:58
  • @JakeSellers It actually depends upon your requirement along with some interesting points as raised by Adrian..stack is already flooded with answers for comparisons for these ..just check few within the mysql domain – swapnesh Apr 01 '13 at 18:03

0 Answers0