andyhajime Posted February 10, 2011 Share Posted February 10, 2011 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.... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 if it's not too late, i suggest that you not store images in the database. assuming the blob is the image data for filename. Quote Link to comment Share on other sites More sharing options...
andyhajime Posted February 10, 2011 Author Share Posted February 10, 2011 The images stored are less then 10kb. Hardly 'stress' mysql. The guy attending the sever said it's so far so good. That's why I need this to work. So I can control the store data. you know how to make it work? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 mysql stress is the least of the worries. but, sorry i don't know how to make it work. maybe this bump will help. Quote Link to comment Share on other sites More sharing options...
andyhajime Posted February 10, 2011 Author Share Posted February 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2011 Share Posted February 11, 2011 You are not fetching the data that mysql_query() returns (hint it returns a result resource, not a data value.) Quote Link to comment Share on other sites More sharing options...
andyhajime Posted February 11, 2011 Author Share Posted February 11, 2011 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; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 $FOUND would be an array. You can't just echo an array. Try print_r(). Quote Link to comment Share on other sites More sharing options...
andyhajime Posted February 11, 2011 Author Share Posted February 11, 2011 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.