Hi All!

I am working with an MSSQL DB which stores images as blob's. When I pull out the blob it seems to be cut off at a fixed length. Every image only displays the top 1/3 or so.

My query is very basic and has no limitations in it for size. Is the information in the DB cut-off? Or do I need to do something inside my query to process a large blob? I'm using ODBC through PHP.

Thank you in advance for ANY help you might be able to offer!

$sqlquery="SELECT image AS theimage FROM IDX_IMAGES_FULL WHERE id='1234'";

 $process=odbc_exec($sqlconnect, $sqlquery);
 $img = odbc_result($process,'theimage');
 $img = $row['theimage'];
 print $img;
7 Years
Discussion Span
Last Post by entercow

This is a PHP question, not MSSQL question. If you store the data properly and retrieve the data properly with PHP then its all good.

You can use

Select DataLength(image) As Sz
From Table

To verify you have the complete image. If the file sizes match then its your PHP that is bad.


Thank you for the DataLength() tip.

The DB is not my own, and I have no control over the content, I can only pull it out.

You are right, DataLength returns the full size of the image, but what is actually getting displayed in the browser is being capped at 4.0Kb on the nose.

I thought this was a problem with my DB query, but you think it's a problem with the PHP? Somewhere the data is getting limited to 4k - ideas?

This is the first time using a blob field.


Probably. I use blob in MSSQL all the time with no problems. Unfortunately I have no PHP experience so you may try the PHP forum :P

If you have any more database questions then go ahead and post back here

Please mark this thread as solved if you feel we have answered the MSSQL end of this question and good luck!


Ok - I've been working on this for the last 20 hours and finally got it solved.

I was going through php.ini settings, odbc functions, and buffering settings endlessly - BUT it came down to a DB query.

Before running the SELECT statement I added

odbc_exec($sqlconnect, "set textsize 65536");

I guess this sets the field size for the Session. I don't really understand why a huge field like the blob would end up being trimmed to 4096 on output - but at this point I'm just glad it's working.


Votes + Comments
I bet this one sucked to debug :P Good job though
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.