Jump to content
xisto Community
Sign in to follow this  
master_bacarra

What Is A Blob (mysql) and how do i use it

Recommended Posts

hey everyone! i just started using mysql so i could integrate it on my site. i'm trying to create a comment section and store the data on mysql. i've defined my table having a field type of varchar with max value 5000. but when i created it on phpmyadmin on my free hosting account, it said that the maximum value for a varchar is just 255. it said that i should use a blob. what is it and how can i access the data using php? i've searched from the net and it said that blob is used for images and document data. and i also found out that the data stored in a blob is a byte... so if i can use blob, how can i convert a text/string to a blob and vice versa. hmm... i'm confused...oh make that binary, not byte. sorry.

Share this post


Link to post
Share on other sites

Just consider blobs to be longer versions of varchars and use them in exactly the same way. In the phpAdmin or the mysqlAdmin (I don't remember which, as I usually do it manuall) you can change the type of field from varchar to blob. Do that, and then treat the rest exactly the same.

Share this post


Link to post
Share on other sites

BLOB and TEXT type as explained in MySQL Language Reference.

A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB differ only in the maximum length of the values they can hold.
The four TEXT types TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT correspond to the four BLOB types and have the same maximum lengths and storage requirements. The only difference between BLOB and TEXT types is that sorting and comparison is performed in case-sensitive fashion for BLOB values and case-insensitive fashion for TEXT values. In other words, a TEXT is a case-insensitive BLOB.


Share this post


Link to post
Share on other sites

so i could use TEXT instead of BLOB in storing the comments? if so, how long is the maximum length for a TEXT in the free hosting accounts? and if ever i am to use a BLOB, how can i convert it to a non-binary form using php and vice versa?

Share this post


Link to post
Share on other sites
Blob vs. varchar vs. textWhat Is A Blob (mysql)

 A blob column type is used to store file contents, like images or pdf's, etc...Any file can go into a blob column type. The different blob types are all basically the same thing except they have different max sizes.

 

If you want to do something like comments, use column type 'text' and leave the maximum value blank. This will allow you to add any amount of text for the comment (for all realistic purposes).

 

I am making a comment system for my site now actually,

-reply by John

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.