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
https://forums.phpfreaks.com/topic/227253-how-to-get-blob-lengthsize/
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.

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;

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.