Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 391

Retrieving and displaying images

$
0
0

Hi,

I have to display images from a mssql databse using PHP and the SQLSRV driver. The images are saved in an image type column as binary. I have been searching for days trying to figure this out. I have the following test code but it is not working. I only get a single image.

Does anyone know how to do this?

$dbHost = '***';
$dbName = '***';
$dbUser = '***';
$dbPass = '***';

$serverName = $dbHost;
$connectionInfo = array("Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPass);
$conn = sqlsrv_connect($serverName, $connectionInfo);

$sql = "SELECT TOP 5 DocMgtImageID, ImageData FROM tbDocMgtImages";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
	header("Content-type: image/jpeg");
	echo $row['ImageData'];
}

sqlsrv_free_stmt( $stmt);

Thank you!



Viewing all articles
Browse latest Browse all 391

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>