🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[web] Best way to store large text strings.

Started by
3 comments, last by demonkoryu 14 years, 6 months ago
Hello, I'm developing a small forum in PHP+MySQL and am having trouble deciding which way would be the best way to store user posts. I have 2 options in mind: Option A: For each forum thread, create a unique ID for the thread in the 'threads_table' table, and in a 'user_posts_table' table, have a column named 'post' and an the associated thread ID. But the main problem is how I should handle long posts? Specifically, the data type associated with the 'post' column. AFAIK, MySQL does not have support for truly variable length fields(I mean, it has VARCHAR(maxLength), but that's still limited, obviously). So basically, the main problem with this method is support for variable length post fields. I mean, I could create a column labeled as VARCHAR(A GAJILLION), because that doesn't seem very efficient :D. Option B: This is what I believe to be the best way. For each thread, have a 'threads_table' with a unique ID for each thread. Now with this unique ID, I would create a unique file, such as [UNIQUE_ID_HERE].someextension. Now I would simply store each post on a single line. Each line would contain space-delimited fields such as username, time of post, and the actual post. The plus of this method, is that it comes with user post queuing built in.(Replies will be displayed in order of the fastest reply time). What method would you suggest? Is there a better way than either I have proposed? Thanks :D
Advertisement
Quote: Original post by fitfool
AFAIK, MySQL does not have support for truly variable length fields
There's the TEXT type, which is like VARCHAR, but variable length ;)

IIRC TEXT can grow up to 65535 characters. If you need longer posts than that, you can use MEDIUMTEXT (2^24 chars max) or LONGTEXT (2^32 chars max) instead.

For future reference, there's also the BLOB type, which is like TEXT, but for any possible kind of data (e.g. a JPEG).
Quote: Original post by Hodgman
Quote: Original post by fitfool
AFAIK, MySQL does not have support for truly variable length fields
There's the TEXT type, which is like VARCHAR, but variable length ;)

IIRC TEXT can grow up to 65535 characters. If you need longer posts than that, you can use MEDIUMTEXT (2^24 chars max) or LONGTEXT (2^32 chars max) instead.

For future reference, there's also the BLOB type, which is like TEXT, but for any possible kind of data (e.g. a JPEG).


Oh cool, didn't see that in the documentation. Sounds great. Thanks a bunch :D
TEXT/NTEXT is getting obsolete. Use VARCHAR(MAX)/NVARCHAR(MAX) instead.
----------------------------------------MagosX.com
Quote: Original post by Magos
TEXT/NTEXT is getting obsolete. Use VARCHAR(MAX)/NVARCHAR(MAX) instead.


This advice is sound for MS SQL Server, but he's using MySQL.

This topic is closed to new replies.

Advertisement