Jump to content

How to get BLOB length/size.


andyhajime

Recommended Posts

Hey there, need some help badly.

 

I'm trying to get the size of the BLOB data in mysql. Did a search and there are like no tutorial on this. Only relevant info was from this page, at the far bottom, it just wrote this (below code). But the writer did not explain how to use it.

 

SELECT OCTET_LENGTH(content) FROM BloBTest WHERE filename='myimage.png'

 

I just give it a trial an error, wrote this, but did not work.

 

$LENGTH = mysql_query("SELECT OCTET_LENGTH(blobdata) FROM thedatabase WHERE id = 'selected_id'");
echo $LENGTH;

 

Please help....

Link to comment
Share on other sites

I've told the client and the webhoster about the problem they might facing, they gave me the green light, and they wanted this method... as long as there's black and white stating I'm not going to be responsible, fine by me.

 

anyone know how to get blob size? please help dearly me.

Link to comment
Share on other sites

You are not fetching the data that mysql_query() returns (hint it returns a result resource, not a data value.)

 

I tried this, still not working. Sorry, my php knowledge is very limited in this.

 

$LENGTH = mysql_query("SELECT OCTET_LENGTH(blobdata) FROM thedatabase WHERE id = 'selected_id'");
$FOUND = mysql_fetch_array($LENGTH);
echo $FOUND;

Link to comment
Share on other sites

Used the print_r() and it returns:

 

#Array ( [0] => 10336 [OCTET_LENGTH(imageraw)] => 10336 )

 

Database recorded:

[bLOB - 10.1  KiB]

 

So complete formula would be:

 

$LENGTH = mysql_query("SELECT OCTET_LENGTH(blobdata) FROM thedatabase WHERE id = 'selected_id'");
$FOUND = mysql_fetch_array($LENGTH);
$RESULTS = $FOUND['0'] / 1024;
echo round($RESULTS, 1).'KiB';

// Results: 10.1KiB

 

 

Thanks Pikachu2000 & PFMaBiSmAd! AWESOME!

I'm so going to write down this snippet so people can use it. There's barely any tutorial online!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.