在php中显示varbinary图像sql server

时间:2017-03-31 15:36:58

标签: php sql-server

我想在sql server上显示存储在varbinary中的图像 我已将其转换为可以看到它 仍然没有给我任何东西 我分享了代码并希望他们可以帮助我

$serverName = "localhost";
$userName = "sa";
$userPassword = "";
$dbName = "Shop";

$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn === false ){
    die( print_r( sqlsrv_errors(), true));
}


$sql = "SELECT Imagen FROM Acessorios";
$query = sqlsrv_query($conn, $sql);

while($result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC))
{
    echo '<img height="300" width="300" src="data:image/jpg;base64,' . base64_encode($result['Imagen'])  . '" >';
    echo "<br/>";

}


sqlsrv_close($conn);

0 个答案:

没有答案