Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Display Images Stored in MSSQL database (using PHP)

Really stuck - need help!



3:08 pm on Oct 11, 2009 (gmt 0)

10+ Year Member

I'm pulling my hair out in frustration at this little bit of php code that I thought would work - yet doesn't. It's meant to take an image ("image" datatype) from a MSSQL (not MySQL) database and display it.

Oddly enough when the url of the script is visted the title bar states "JPEG Image, 1024x768 pixels" (Firefox) which is spot on - yet all that appears is a completely blank/white image (1024x768 pixels, but only 4.00 KB in size).

Is there something wrong with the script?

$myUser = "sa";
$myPass = "#*$!#*$!X";
$myDB = "YYYYY";

$dbhandle = mssql_connect($myServer, $myUser, $myPass, true) or die("Error1");
$selected = mssql_select_db($myDB, $dbhandle) or die("Error2");
$query = "SELECT image FROM abc WHERE id=999";
$result = mssql_query($query,$dbhandle);

$content=mssql_result($result, 0, "image");
header('Content-type: image/jpeg');
echo $content;


6:16 pm on Oct 11, 2009 (gmt 0)

10+ Year Member

Please ignore the last post - the problem was due to the mssql.textlimit and mssql.textsize settings in php.ini (they default to 4096 hence only a small part of the image was actually being extracted from the database.

Featured Threads

Hot Threads This Week

Hot Threads This Month