[英]how to properly get a blob(MAX) image from SQL db
When i try to get a image as blob i get this response: The Response content must be a string or object implementing __toString(), "boolean" given. 当我尝试将图像作为blob获取此响应时:Response内容必须是实现__toString()的字符串或对象,给出“boolean”。
my code is as following, The GET query 我的代码如下,GET查询
function GET_shopimages($shopid){
$currentUserName = Auth::user()->name;
$query = "SELECT * FROM srms_dam.dbo.pictures WHERE srms_dam.dbo.pictures.shopid = (?) ";
$parameters = array((int) $shopid);
return executeImageObjectQuery($query, $parameters);
}
the executeImageObjectQuery: executeImageObjectQuery:
function executeImageObjectQuery($inputQuery, $stagingParameters){
$conn = buildConnection();
if( $conn ) {
$query = $inputQuery;
$result = sqlsrv_query($conn, $query, $stagingParameters);
$detailresult = sqlsrv_fetch_array($result); echo '<img
src="data:image/jpeg;base64,'.base64_encode( $result['picture'] ).'"/>';
sqlsrv_close ($conn);
return $detailresult;
} else {
return response('Cannot build database connection', 503);
}
}
I already looked at the different questions surrounding blob but could not find an answer, any help would be greatly appreciated. 我已经看过围绕blob的不同问题,但找不到答案,任何帮助都会非常感激。 the Query worked in the database itself.
Query在数据库本身中工作。 $detailresult = $result here.
$ detailresult = $ result here。
(if i need to insert my routing code please let me know) (如果我需要插入我的路由代码,请告诉我)
Since this took to long to figure out i decided to just upload the picture path in the db and go from there. 由于这花了很长时间才弄清楚我决定只上传数据库中的图片路径并从那里开始。 Question still remains though because i'm sure i am not the only one having this issue
问题仍然存在,因为我确定我不是唯一有此问题的人
There is probably a typo error: 可能存在拼写错误:
$result['picture']
You fetch results into $detailresult
and you should use it: 您将结果提取到
$detailresult
,您应该使用它:
$detailresult['picture']
Still, you may get some errors from your sql query, therefore I would use sqlsrv_errors
. 但是,您可能会从SQL查询中获得一些错误,因此我会使用
sqlsrv_errors
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.