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!